mirror of
https://github.com/dylanaraps/sowm.git
synced 2025-05-19 09:30:24 -07:00
clean up
This commit is contained in:
parent
e53f49cc2d
commit
f5f3c4aa06
92
sowm.c
92
sowm.c
@ -97,22 +97,20 @@ void win_add(Window w) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
if (head == NULL) {
|
if (head == NULL) {
|
||||||
c->next = NULL;
|
|
||||||
c->prev = NULL;
|
c->prev = NULL;
|
||||||
c->win = w;
|
|
||||||
head = c;
|
head = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
for(t=head;t->next;t=t->next);
|
for (t=head;t->next;t=t->next);
|
||||||
|
|
||||||
c->next = NULL;
|
|
||||||
c->prev = t;
|
c->prev = t;
|
||||||
c->win = w;
|
|
||||||
t->next = c;
|
t->next = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = c;
|
c->next = NULL;
|
||||||
|
c->win = w;
|
||||||
|
cur = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ws_go(const Arg arg) {
|
void ws_go(const Arg arg) {
|
||||||
@ -190,10 +188,10 @@ void destroy_notify(XEvent *e) {
|
|||||||
|
|
||||||
XDestroyWindowEvent *ev = &e->xdestroywindow;
|
XDestroyWindowEvent *ev = &e->xdestroywindow;
|
||||||
|
|
||||||
for(c=head;c;c=c->next)
|
for (c=head;c;c=c->next)
|
||||||
if(ev->window == c->win) i++;
|
if(ev->window == c->win) i++;
|
||||||
|
|
||||||
if(i == 0)
|
if (i == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
win_del(ev->window);
|
win_del(ev->window);
|
||||||
@ -228,22 +226,20 @@ void key_grab() {
|
|||||||
int i;
|
int i;
|
||||||
KeyCode code;
|
KeyCode code;
|
||||||
|
|
||||||
for(i=0;i<TABLENGTH(keys);++i) {
|
for(i=0;i<TABLENGTH(keys);++i)
|
||||||
if ((code = XKeysymToKeycode(dis, keys[i].keysym)))
|
if ((code = XKeysymToKeycode(dis, keys[i].keysym)))
|
||||||
XGrabKey(dis, code, keys[i].mod, root,
|
XGrabKey(dis, code, keys[i].mod, root,
|
||||||
True, GrabModeAsync, GrabModeAsync);
|
True, GrabModeAsync, GrabModeAsync);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_press(XEvent *e) {
|
void key_press(XEvent *e) {
|
||||||
int i;
|
int i;
|
||||||
XKeyEvent ke = e->xkey;
|
XKeyEvent ke = e->xkey;
|
||||||
KeySym keysym = XkbKeycodeToKeysym(dis,ke.keycode,0,0);
|
KeySym keysym = XkbKeycodeToKeysym(dis,ke.keycode,0,0);
|
||||||
|
|
||||||
for(i=0;i<TABLENGTH(keys);++i) {
|
for(i=0;i<TABLENGTH(keys);++i) {
|
||||||
if(keys[i].keysym == keysym && keys[i].mod == ke.state) {
|
if (keys[i].keysym == keysym && keys[i].mod == ke.state)
|
||||||
keys[i].function(keys[i].arg);
|
keys[i].function(keys[i].arg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,8 +274,7 @@ void button_release(XEvent *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void win_kill() {
|
void win_kill() {
|
||||||
if(cur != NULL)
|
if (cur != NULL) XKillClient(dis, cur->win);
|
||||||
XKillClient(dis, cur->win);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void map_request(XEvent *e) {
|
void map_request(XEvent *e) {
|
||||||
@ -287,7 +282,7 @@ void map_request(XEvent *e) {
|
|||||||
client *c;
|
client *c;
|
||||||
|
|
||||||
// For fullscreen mplayer (and maybe some other program)
|
// For fullscreen mplayer (and maybe some other program)
|
||||||
for(c=head;c;c=c->next)
|
for (c=head;c;c=c->next)
|
||||||
if(ev->window == c->win) {
|
if(ev->window == c->win) {
|
||||||
XMapWindow(dis,ev->window);
|
XMapWindow(dis,ev->window);
|
||||||
return;
|
return;
|
||||||
@ -317,39 +312,39 @@ void win_del(Window w) {
|
|||||||
client *c;
|
client *c;
|
||||||
|
|
||||||
for(c=head;c;c=c->next) {
|
for(c=head;c;c=c->next) {
|
||||||
if(c->win == w) {
|
if (c->win != w) continue;
|
||||||
if (c->prev == NULL && c->next == NULL) {
|
|
||||||
free(head);
|
|
||||||
|
|
||||||
head = NULL;
|
if (c->prev == NULL && c->next == NULL) {
|
||||||
cur = NULL;
|
free(head);
|
||||||
|
|
||||||
ws_save(curr_desk);
|
head = NULL;
|
||||||
return;
|
cur = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (c->prev == NULL) {
|
|
||||||
head = c->next;
|
|
||||||
c->next->prev = NULL;
|
|
||||||
cur = c->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (c->next == NULL) {
|
|
||||||
c->prev->next = NULL;
|
|
||||||
cur = c->prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
c->prev->next = c->next;
|
|
||||||
c->next->prev = c->prev;
|
|
||||||
cur = c->prev;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(c);
|
|
||||||
ws_save(curr_desk);
|
ws_save(curr_desk);
|
||||||
win_update();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c->prev == NULL) {
|
||||||
|
head = c->next;
|
||||||
|
c->next->prev = NULL;
|
||||||
|
cur = c->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (c->next == NULL) {
|
||||||
|
c->prev->next = NULL;
|
||||||
|
cur = c->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
c->prev->next = c->next;
|
||||||
|
c->next->prev = c->prev;
|
||||||
|
cur = c->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(c);
|
||||||
|
ws_save(curr_desk);
|
||||||
|
win_update();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,9 +374,9 @@ void wm_setup() {
|
|||||||
|
|
||||||
key_grab();
|
key_grab();
|
||||||
|
|
||||||
mode = 0;
|
mode = 0;
|
||||||
head = NULL;
|
head = NULL;
|
||||||
cur = NULL;
|
cur = NULL;
|
||||||
|
|
||||||
for(i=0;i<TABLENGTH(desktops);++i) {
|
for(i=0;i<TABLENGTH(desktops);++i) {
|
||||||
desktops[i].mode = mode;
|
desktops[i].mode = mode;
|
||||||
@ -390,7 +385,7 @@ void wm_setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Arg arg = {.i = 1};
|
const Arg arg = {.i = 1};
|
||||||
curr_desk = arg.i;
|
curr_desk = arg.i;
|
||||||
ws_go(arg);
|
ws_go(arg);
|
||||||
|
|
||||||
XSelectInput(dis, root, SubstructureNotifyMask|SubstructureRedirectMask);
|
XSelectInput(dis, root, SubstructureNotifyMask|SubstructureRedirectMask);
|
||||||
@ -422,7 +417,7 @@ void wm_init() {
|
|||||||
if (events[ev.type]) events[ev.type](&ev);
|
if (events[ev.type]) events[ev.type](&ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main() {
|
||||||
if ((dis = XOpenDisplay(NULL))) {
|
if ((dis = XOpenDisplay(NULL))) {
|
||||||
wm_setup();
|
wm_setup();
|
||||||
wm_init();
|
wm_init();
|
||||||
@ -432,4 +427,3 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user