Mercurial > aewl
comparison dwm.c @ 758:bc512840e5a5
removed union arg (using const char* cmd now)
whole bar toggles view if clicked now
author | meillo@marmaro.de |
---|---|
date | Fri, 30 May 2008 21:57:51 +0200 |
parents | bff1012527b3 |
children |
comparison
equal
deleted
inserted
replaced
757:427608ef0687 | 758:bc512840e5a5 |
---|---|
56 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ | 56 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
57 enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */ | 57 enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */ |
58 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ | 58 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ |
59 enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ | 59 enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
60 | 60 |
61 typedef union { | |
62 const char *cmd; | |
63 int i; | |
64 } Arg; /* argument type */ | |
65 | |
66 typedef struct { | 61 typedef struct { |
67 int ascent; | 62 int ascent; |
68 int descent; | 63 int descent; |
69 int height; | 64 int height; |
70 XFontSet set; | 65 XFontSet set; |
109 | 104 |
110 | 105 |
111 typedef struct { | 106 typedef struct { |
112 unsigned long mod; | 107 unsigned long mod; |
113 KeySym keysym; | 108 KeySym keysym; |
114 void (*func)(Arg *arg); | 109 void (*func)(const char* cmd); |
115 Arg arg; | 110 const char* cmd; |
116 } Key; | 111 } Key; |
117 | 112 |
118 | 113 |
119 #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) | 114 #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) |
120 #define MOUSEMASK (BUTTONMASK | PointerMotionMask) | 115 #define MOUSEMASK (BUTTONMASK | PointerMotionMask) |
158 /* client.c */ | 153 /* client.c */ |
159 void configure(Client *c); /* send synthetic configure event */ | 154 void configure(Client *c); /* send synthetic configure event */ |
160 void focus(Client *c); /* focus c, c may be NULL */ | 155 void focus(Client *c); /* focus c, c may be NULL */ |
161 Client *getclient(Window w); /* return client of w */ | 156 Client *getclient(Window w); /* return client of w */ |
162 Bool isprotodel(Client *c); /* returns True if c->win supports wmatom[WMDelete] */ | 157 Bool isprotodel(Client *c); /* returns True if c->win supports wmatom[WMDelete] */ |
163 void killclient(); /* kill c nicely */ | |
164 void manage(Window w, XWindowAttributes *wa); /* manage new client */ | 158 void manage(Window w, XWindowAttributes *wa); /* manage new client */ |
165 void resize(Client *c, Bool sizehints); /* resize c*/ | 159 void resize(Client *c, Bool sizehints); /* resize c*/ |
166 void updatesizehints(Client *c); /* update the size hint variables of c */ | 160 void updatesizehints(Client *c); /* update the size hint variables of c */ |
167 void updatetitle(Client *c); /* update the name of c */ | 161 void updatetitle(Client *c); /* update the name of c */ |
168 void unmanage(Client *c); /* destroy c */ | 162 void unmanage(Client *c); /* destroy c */ |
176 /* event.c */ | 170 /* event.c */ |
177 void grabkeys(void); /* grab all keys defined in config.h */ | 171 void grabkeys(void); /* grab all keys defined in config.h */ |
178 void procevent(void); /* process pending X events */ | 172 void procevent(void); /* process pending X events */ |
179 | 173 |
180 /* main.c */ | 174 /* main.c */ |
181 void quit(); /* quit dwm nicely */ | |
182 void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ | 175 void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ |
183 int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ | 176 int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ |
184 | 177 |
185 /* tag.c */ | 178 /* tag.c */ |
186 void initrregs(void); /* initialize regexps of rules defined in config.h */ | 179 void initrregs(void); /* initialize regexps of rules defined in config.h */ |
187 Client *getnext(Client *c); /* returns next visible client */ | 180 Client *getnext(Client *c); /* returns next visible client */ |
188 void settags(Client *c, Client *trans); /* sets tags of c */ | 181 void settags(Client *c, Client *trans); /* sets tags of c */ |
189 void toggletag(); /* toggles c tags with arg's index */ | |
190 | 182 |
191 /* util.c */ | 183 /* util.c */ |
192 void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ | 184 void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ |
193 void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ | 185 void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ |
194 void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */ | |
195 | 186 |
196 /* view.c */ | 187 /* view.c */ |
197 void detach(Client *c); /* detaches c from global client list */ | 188 void detach(Client *c); /* detaches c from global client list */ |
198 void dofloat(void); /* arranges all windows floating */ | 189 void dofloat(void); /* arranges all windows floating */ |
199 void dotile(void); /* arranges all windows tiled */ | 190 void dotile(void); /* arranges all windows tiled */ |
200 void domax(void); /* arranges all windows fullscreen */ | 191 void domax(void); /* arranges all windows fullscreen */ |
201 void focusnext(); /* focuses next visible client, arg is ignored */ | 192 Bool isvisible(Client *c); /* returns True if client is visible */ |
193 void restack(void); /* restores z layers of all clients */ | |
194 | |
195 | |
196 void toggleview(); /* toggle the viewed tag */ | |
197 void focusnext(); /* focuses next visible client */ | |
198 void zoom(); /* zooms the focused client to master area */ | |
199 void killclient(); /* kill c nicely */ | |
200 void quit(); /* quit dwm nicely */ | |
201 void togglemode(); /* toggles global arrange function (dotile/dofloat) */ | |
202 void togglefloat(); /* toggles focusesd client between floating/non-floating state */ | |
202 void incnmaster(); /* increments nmaster */ | 203 void incnmaster(); /* increments nmaster */ |
203 void decnmaster(); /* decrements nmaster */ | 204 void decnmaster(); /* decrements nmaster */ |
204 Bool isvisible(Client *c); /* returns True if client is visible */ | 205 void toggletag(); /* toggles c tag */ |
205 void restack(void); /* restores z layers of all clients */ | 206 void spawn(const char* cmd); /* forks a new subprocess with cmd */ |
206 void togglefloat(); /* toggles focusesd client between floating/non-floating state */ | |
207 void togglemode(); /* toggles global arrange function (dotile/dofloat) */ | |
208 void toggleview(); /* views the tag with arg's index */ | |
209 void zoom(); /* zooms the focused client to master area, arg is ignored */ | |
210 | 207 |
211 | 208 |
212 | 209 |
213 | 210 |
214 | 211 |
536 va_end(ap); | 533 va_end(ap); |
537 exit(EXIT_FAILURE); | 534 exit(EXIT_FAILURE); |
538 } | 535 } |
539 | 536 |
540 void | 537 void |
541 spawn(Arg *arg) { | 538 spawn(const char* cmd) { |
542 static char *shell = NULL; | 539 static char *shell = NULL; |
543 | 540 |
544 if(!shell && !(shell = getenv("SHELL"))) | 541 if(!shell && !(shell = getenv("SHELL"))) |
545 shell = "/bin/sh"; | 542 shell = "/bin/sh"; |
546 if(!arg->cmd) | 543 if(!cmd) |
547 return; | 544 return; |
548 /* The double-fork construct avoids zombie processes and keeps the code | 545 /* The double-fork construct avoids zombie processes and keeps the code |
549 * clean from stupid signal handlers. */ | 546 * clean from stupid signal handlers. */ |
550 if(fork() == 0) { | 547 if(fork() == 0) { |
551 if(fork() == 0) { | 548 if(fork() == 0) { |
552 if(dpy) | 549 if(dpy) |
553 close(ConnectionNumber(dpy)); | 550 close(ConnectionNumber(dpy)); |
554 setsid(); | 551 setsid(); |
555 execl(shell, shell, "-c", arg->cmd, (char *)NULL); | 552 execl(shell, shell, "-c", cmd, (char *)NULL); |
556 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd); | 553 fprintf(stderr, "dwm: execl '%s -c %s'", shell, cmd); |
557 perror(" failed"); | 554 perror(" failed"); |
558 } | 555 } |
559 exit(0); | 556 exit(0); |
560 } | 557 } |
561 wait(0); | 558 wait(0); |
754 } | 751 } |
755 | 752 |
756 static void | 753 static void |
757 buttonpress(XEvent *e) { | 754 buttonpress(XEvent *e) { |
758 int x; | 755 int x; |
759 Arg a; | 756 int i; |
760 Client *c; | 757 Client *c; |
761 XButtonPressedEvent *ev = &e->xbutton; | 758 XButtonPressedEvent *ev = &e->xbutton; |
762 | 759 |
763 if(barwin == ev->window) { | 760 if(barwin == ev->window) { |
764 x = 0; | 761 if(ev->button == Button1) { |
765 for(a.i = 0; a.i < ntags; a.i++) { | 762 toggleview(); |
766 x += textw(tags[a.i]); | 763 } |
767 if(ev->x < x) { | 764 return; |
768 if(ev->button == Button1) { | 765 } else if((c = getclient(ev->window))) { |
769 toggleview(); | |
770 } | |
771 return; | |
772 } | |
773 } | |
774 if(ev->x < x + bmw) | |
775 if (ev->button == Button1) { | |
776 togglemode(NULL); | |
777 } | |
778 } | |
779 else if((c = getclient(ev->window))) { | |
780 focus(c); | 766 focus(c); |
781 if(CLEANMASK(ev->state) != MODKEY) | 767 if(CLEANMASK(ev->state) != MODKEY) |
782 return; | 768 return; |
783 if(ev->button == Button1 && (arrange == dofloat || c->isfloat)) { | 769 if(ev->button == Button1 && (arrange == dofloat || c->isfloat)) { |
784 restack(); | 770 restack(); |
785 movemouse(c); | 771 movemouse(c); |
786 } | 772 } else if(ev->button == Button3 && (arrange == dofloat || c->isfloat) && !c->isfixed) { |
787 else if(ev->button == Button2) | |
788 zoom(NULL); | |
789 else if(ev->button == Button3 && (arrange == dofloat || c->isfloat) && | |
790 !c->isfixed) { | |
791 restack(); | 773 restack(); |
792 resizemouse(c); | 774 resizemouse(c); |
793 } | 775 } |
794 } | 776 } |
795 } | 777 } |
828 if(!isvisible(c)) | 810 if(!isvisible(c)) |
829 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); | 811 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); |
830 } | 812 } |
831 else | 813 else |
832 arrange(); | 814 arrange(); |
833 } | 815 } else { |
834 else { | |
835 wc.x = ev->x; | 816 wc.x = ev->x; |
836 wc.y = ev->y; | 817 wc.y = ev->y; |
837 wc.width = ev->width; | 818 wc.width = ev->width; |
838 wc.height = ev->height; | 819 wc.height = ev->height; |
839 wc.border_width = ev->border_width; | 820 wc.border_width = ev->border_width; |
888 | 869 |
889 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); | 870 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); |
890 for(i = 0; i < len; i++) { | 871 for(i = 0; i < len; i++) { |
891 if(keysym == key[i].keysym && CLEANMASK(key[i].mod) == CLEANMASK(ev->state)) { | 872 if(keysym == key[i].keysym && CLEANMASK(key[i].mod) == CLEANMASK(ev->state)) { |
892 if(key[i].func) | 873 if(key[i].func) |
893 key[i].func(&key[i].arg); | 874 key[i].func(key[i].cmd); |
894 } | 875 } |
895 } | 876 } |
896 } | 877 } |
897 | 878 |
898 static void | 879 static void |