diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e39f59..6a89d1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,8 @@ set(wmfs_src config.c event.c util.c - layout.c) + layout.c + tag.c) # Set the executable from the wmfs_src add_executable(wmfs ${wmfs_src}) diff --git a/config.c b/config.c index 6758564..62d972b 100644 --- a/config.c +++ b/config.c @@ -36,20 +36,21 @@ func_name_list_t func_list[] = { - {"spawn", spawn}, - {"killclient", killclient}, - {"client_switch", wswitch}, - {"togglemax", togglemax}, - {"keymovex", keymovex}, - {"keymovey", keymovey}, - {"keyresize", keyresize}, - {"layoutswitch",layoutswitch}, - {"tag", tag}, - {"tagtransfert", tagtransfert}, - {"set_mwfact", set_mwfact}, - {"set_nmaster", set_nmaster}, - {"quit", quit}, - {"togglebarpos", togglebarpos} + {"spawn", uicb_spawn }, + {"killclient", uicb_killclient }, + {"client_prev", uicb_client_prev }, + {"client_next", uicb_client_next }, + {"togglemax", uicb_togglemax }, + {"layout_next", uicb_layout_next }, + {"layout_prev", uicb_layout_prev }, + {"tag", uicb_tag }, + {"tag_next", uicb_tag_next }, + {"tag_prev", uicb_tag_prev }, + {"tagtransfert", uicb_tagtransfert }, + {"set_mwfact", uicb_set_mwfact }, + {"set_nmaster", uicb_set_nmaster }, + {"quit", uicb_quit }, + {"togglebarpos", uicb_togglebarpos } }; func_name_list_t layout_list[] = diff --git a/event.c b/event.c index 7ad71a3..25a49fc 100644 --- a/event.c +++ b/event.c @@ -62,9 +62,9 @@ buttonpress(XEvent ev) if(ev.xbutton.button == Button2) { if(tags[seltag].layout.func == tile) - tile_switch(NULL); + uicb_tile_switch(NULL); else - togglemax(NULL); + uicb_togglemax(NULL); } } /* BUTTON 3 */ @@ -85,7 +85,7 @@ buttonpress(XEvent ev) /* BUTTON 1 */ { if(ev.xbutton.button == Button1) - killclient(NULL); + uicb_killclient(NULL); } /* BUTTON 2 AND 3 */ { @@ -93,9 +93,9 @@ buttonpress(XEvent ev) || ev.xbutton.button == Button3) { if(tags[seltag].layout.func == tile) - tile_switch(NULL); + uicb_tile_switch(NULL); else - togglemax(NULL); + uicb_togglemax(NULL); } } } @@ -121,9 +121,9 @@ buttonpress(XEvent ev) if(ev.xbutton.button == Button2) { if(tags[seltag].layout.func == tile) - tile_switch(NULL); + uicb_tile_switch(NULL); else - togglemax(NULL); + uicb_togglemax(NULL); } } /* BUTTON 3 */ @@ -157,12 +157,12 @@ buttonpress(XEvent ev) /* BUTTON 1 */ { if(ev.xbutton.button == Button1) - tag(s); + uicb_tag(s); } /* BUTTON 2 */ { if(ev.xbutton.button == Button3) - tagtransfert(s); + uicb_tagtransfert(s); } } } @@ -176,12 +176,12 @@ buttonpress(XEvent ev) /* BUTTON 4 (UP) */ { if(ev.xbutton.button == Button4) - tag("+1"); + uicb_tag("+1"); } /* BUTTON 5 (UP) */ { if (ev.xbutton.button == Button5) - tag("-1"); + uicb_tag("-1"); } } @@ -203,13 +203,13 @@ buttonpress(XEvent ev) { if(ev.xbutton.button == Button1 || ev.xbutton.button == Button4) - layoutswitch("+"); + layoutswitch(True); } /* BUTTON 3 / 5 */ { if(ev.xbutton.button == Button3 || ev.xbutton.button == Button5) - layoutswitch("-"); + layoutswitch(False); } } @@ -228,12 +228,12 @@ buttonpress(XEvent ev) /* BUTTON 4 */ { if(ev.xbutton.button == Button4) - tag("+1"); + uicb_tag("+1"); } /* BUTTON 5 */ { if(ev.xbutton.button == Button5) - tag("-1"); + uicb_tag("-1"); } } diff --git a/layout.c b/layout.c index aa335b5..40e6da2 100644 --- a/layout.c +++ b/layout.c @@ -56,7 +56,7 @@ freelayout(void) /* Improved ! :) */ void -layoutswitch(char *cmd) +layoutswitch(Bool b) { int i; @@ -65,9 +65,9 @@ layoutswitch(char *cmd) if(tags[seltag].layout.symbol == conf.layout[i].symbol && tags[seltag].layout.func == conf.layout[i].func) { - if(cmd[0] == '+') + if(b) tags[seltag].layout = conf.layout[(i + 1) % conf.nlayout]; - else if(cmd[0] == '-') + else tags[seltag].layout = conf.layout[(i + conf.nlayout - 1) % conf.nlayout]; break; } @@ -77,6 +77,22 @@ layoutswitch(char *cmd) return; } +void +uicb_layout_next(char *cmd) +{ + layoutswitch(True); + + return; +} + +void +uicb_layout_prev(char *cmd) +{ + layoutswitch(False); + + return; +} + void maxlayout(void) { @@ -111,7 +127,7 @@ nexttiled(Client *c) } void -set_mwfact(char *cmd) +uicb_set_mwfact(char *cmd) { double c; @@ -128,7 +144,7 @@ set_mwfact(char *cmd) } void -set_nmaster(char *cmd) +uicb_set_nmaster(char *cmd) { int n = atoi(cmd); @@ -216,7 +232,7 @@ tile(void) } void -tile_switch(char *cmd) +uicb_tile_switch(char *cmd) { Client *c; @@ -234,7 +250,7 @@ tile_switch(char *cmd) } void -togglemax(char *cmd) +uicb_togglemax(char *cmd) { if(!sel || ishide(sel) || sel->hint) return; diff --git a/tag.c b/tag.c new file mode 100644 index 0000000..58ce0e2 --- /dev/null +++ b/tag.c @@ -0,0 +1,95 @@ +/* +* tag.c +* Copyright © 2008 Martin Duquesnoy +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are +* met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following disclaimer +* in the documentation and/or other materials provided with the +* distribution. +* * Neither the name of the nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "wmfs.h" + + +/* if cmd is +X or -X, this is just switch + * else {1, 2.. 9} it's go to the wanted tag. */ +void +uicb_tag(char *cmd) +{ + int tmp = atoi(cmd); + + if(!tmp) + tmp = 1; + + if(cmd[0] == '+' || cmd[0] == '-') + { + if(tmp + seltag < 1 + || tmp + seltag > conf.ntag) + return; + seltag += tmp; + } + else + { + if(tmp == seltag + || tmp > conf.ntag) + return; + seltag = tmp; + } + arrange(); + + return; +} + +void +uicb_tag_next(char *cmd) +{ + uicb_tag("+1"); + + return; +} + +void +uicb_tag_prev(char *cmd) +{ + uicb_tag("-1"); + + return; +} + +void +uicb_tagtransfert(char *cmd) +{ + int n = atoi(cmd); + + if(!sel) + return; + if(!n) + n = 1; + + sel->tag = n; + arrange(); + + return; +} diff --git a/util.c b/util.c index 454290a..16d0e06 100644 --- a/util.c +++ b/util.c @@ -44,7 +44,7 @@ emalloc(unsigned int element, unsigned int size) } void -spawn(char *cmd) +uicb_spawn(char *cmd) { if(!strlen(cmd)) return; diff --git a/wmfs.c b/wmfs.c index f99f3ac..4232470 100644 --- a/wmfs.c +++ b/wmfs.c @@ -74,6 +74,64 @@ clientpertag(int tag) return i; } +/* True : next + * False : prev */ +void +client_switch(Bool b) +{ + Client *c; + + if(!sel || ishide(sel)) + return; + if(b) + { + for(c = sel->next; c && ishide(c); c = c->next); + if(!c) + for(c = clients; c && ishide(c); c = c->next); + if(c) + { + focus(c); + if(!c->tile) + raiseclient(c); + } + } + else + { + for(c = sel->prev; c && ishide(c); c = c->prev); + if(!c) + { + for(c = clients; c && c->next; c = c->next); + for(; c && ishide(c); c = c->prev); + } + if(c) + { + focus(c); + if(!c->tile) + raiseclient(c); + } + } + updateall(); + + return; +} + +void +uicb_client_prev(char *cmd) +{ + client_switch(False); + + return; +} + +void +uicb_client_next(char *cmd) +{ + client_switch(True); + + return; +} + + void detach(Client *c) { @@ -369,58 +427,7 @@ ishide(Client *c) } void -keymovex(char *cmd) -{ - int tmp; - - if(sel && cmd && !ishide(sel) && !sel->max && !sel->tile) - { - tmp = sel->x + atoi(cmd); - moveresize(sel, tmp, sel->y, sel->w, sel->h, True); - } - - return; -} - -void -keymovey(char *cmd) -{ - int tmp; - - if(sel && cmd && !ishide(sel) && !sel->max && !sel->tile) - { - tmp = sel->y + atoi(cmd); - moveresize(sel, sel->x, tmp, sel->w, sel->h, True); - } - - return; -} - -void -keyresize(char *cmd) -{ - int temph = 0, tempw = 0, - modh = 0, modw = 0, tmp = 0; - - if(sel && !ishide(sel) && !sel->max && !sel->tile) - { - switch(cmd[1]) - { - case 'h': tmp = (cmd[0] == '+') ? 5 : -5; modh = tmp; break; - case 'w': tmp = (cmd[0] == '+') ? 5 : -5; modw = tmp; break; - } - temph = sel->h + modh; - tempw = sel->w + modw; - temph = (temph < 10) ? 10 : temph; - tempw = (tempw < 10) ? 10 : tempw; - moveresize(sel, sel->x, sel->y, tempw, temph, True); - } - - return; -} - -void -killclient(char *cmd) +uicb_killclient(char *cmd) { XEvent ev; @@ -710,7 +717,7 @@ moveresize(Client *c, int x, int y, int w, int h, bool r) } void -quit(char *cmd) +uicb_quit(char *cmd) { exiting = True; @@ -849,53 +856,8 @@ setsizehints(Client *c) return; } -/* if cmd is +X or -X, this is just switch - * else {1, 2.. 9} it's go to the wanted tag. */ void -tag(char *cmd) -{ - int tmp = atoi(cmd); - - if(!tmp) - tmp = 1; - - if(cmd[0] == '+' || cmd[0] == '-') - { - if(tmp + seltag < 1 - || tmp + seltag > conf.ntag) - return; - seltag += tmp; - } - else - { - if(tmp == seltag - || tmp > conf.ntag) - return; - seltag = tmp; - } - arrange(); - - return; -} - -void -tagtransfert(char *cmd) -{ - int n = atoi(cmd); - - if(!sel) - return; - if(!n) - n = 1; - - sel->tag = n; - arrange(); - - return; -} - -void -togglebarpos(char *cmd) +uicb_togglebarpos(char *cmd) { int i; @@ -1116,45 +1078,6 @@ updatetitle(Client *c) return; } -void -wswitch(char *cmd) -{ - Client *c; - - if(!sel || ishide(sel)) - return; - if(cmd[0] == '+') - { - for(c = sel->next; c && ishide(c); c = c->next); - if(!c) - for(c = clients; c && ishide(c); c = c->next); - if(c) - { - focus(c); - if(!c->tile) - raiseclient(c); - } - } - else if(cmd[0] == '-') - { - for(c = sel->prev; c && ishide(c); c = c->prev); - if(!c) - { - for(c = clients; c && c->next; c = c->next); - for(; c && ishide(c); c = c->prev); - } - if(c) - { - focus(c); - if(!c->tile) - raiseclient(c); - } - } - updateall(); - - return; -} - int main(int argc, char **argv) { diff --git a/wmfs.h b/wmfs.h index bbc245a..76a516e 100644 --- a/wmfs.h +++ b/wmfs.h @@ -183,7 +183,6 @@ typedef struct unsigned int button; } name_to_uint_t; - /* Enum */ enum { CurNormal, CurResize, CurMove, CurLast }; enum { WMState, WMProtocols, WMName, WMDelete, WMLast }; @@ -210,23 +209,32 @@ void getevent(void); /* util.c */ void *emalloc(unsigned int elemet, unsigned int size); -void spawn(char *cmd); +void uicb_spawn(char *cmd); + +/* tag.c */ +void uicb_tag(char *cmd); +void uicb_tag_next(char *cmd); +void uicb_tag_prev(char *cmd); +void uicb_tagtransfert(char *cmd); /* layout.c */ void freelayout(void); -void layoutswitch(char *cmd); +void layoutswitch(Bool b); void maxlayout(void); Client* nexttiled(Client *c); -void set_mwfact(char *cmd); -void set_nmaster(char *cmd); void tile(void); -void tile_switch(char *cmd); -void togglemax(char *cmd); +void uicb_tile_switch(char *cmd); +void uicb_togglemax(char *cmd); +void uicb_layout_prev(char *cmd); +void uicb_layout_next(char *cmd); +void uicb_set_mwfact(char *cmd); +void uicb_set_nmaster(char *cmd); /* wmfs.c */ void arrange(void); void attach(Client *c); int clientpertag(int tag); +void client_switch(Bool c); void detach(Client *c); int errorhandler(Display *d, XErrorEvent *event); int errorhandlerdummy(Display *d, XErrorEvent *event); @@ -240,24 +248,16 @@ void grabkeys(void); void hide(Client *c); void init(void); Bool ishide(Client *c); -void keymovex(char *cmd); -void keymovey(char *cmd); -void keyresize(char *cmd); -void killclient(char *cmd); void mainloop(void); void mapclient(Client *c); void manage(Window w, XWindowAttributes *wa); void mouseaction(Client *c, int x, int y, int type); void moveresize(Client *c, int x, int y, int w, int h, bool r); -void quit(char *cmd); void raiseclient(Client *c); void scan(void); void setborder(Window win, int color); void setwinstate(Window win, long state); void setsizehints(Client *c); -void tag(char *cmd); -void tagtransfert(char *cmd); -void togglebarpos(char *cmd); void unhide(Client *c); void unmanage(Client *c); void updatebar(void); @@ -265,7 +265,11 @@ void updatebutton(Bool c); void unmapclient(Client *c); void updateall(void); void updatetitle(Client *c); -void wswitch(char *cmd); +void uicb_client_prev(char *cmd); +void uicb_client_next(char *cmd); +void uicb_killclient(char *cmd); +void uicb_quit(char *cmd); +void uicb_togglebarpos(char *cmd); /* Variables */ diff --git a/wmfsrc b/wmfsrc index fc51a79..86713da 100644 --- a/wmfsrc +++ b/wmfsrc @@ -95,54 +95,37 @@ buttons keys { # general keybind - key { mod = {"Control"} key = "Return" func = "spawn" cmd = "urxvt" } key { mod = {"Alt"} key = "q" func = "killclient" } key { mod = {"Control"} key = "m" func = "togglemax" } key { mod = {"Control"} key = "b" func = "togglebarpos" } - key { mod = {"Alt"} key = "Tab" func = "client_switch" cmd = "+" } - key { mod = {"Alt","Shift"} key = "Tab" func = "client_switch" cmd = "-" } - key { mod = {"Control"} key = "Right" func = "tag" cmd = "+1" } - key { mod = {"Control"} key = "Left" func = "tag" cmd = "-1" } - key { mod = {"Control"} key = "Up" func = "layoutswitch" cmd = "+" } - key { mod = {"Control"} key = "Down" func = "layoutswitch" cmd = "-" } + key { mod = {"Alt"} key = "Tab" func = "client_next" } + key { mod = {"Alt","Shift"} key = "Tab" func = "client_prev" } + key { mod = {"Control"} key = "Right" func = "tag_next" } + key { mod = {"Control"} key = "Left" func = "tag_prev" } + key { mod = {"Control"} key = "Up" func = "layout_next" } + key { mod = {"Control"} key = "Down" func = "layout_prev" } key { mod = {"Alt"} key = "l" func = "set_mwfact" cmd = "+0.025" } key { mod = {"Alt"} key = "h" func = "set_mwfact" cmd = "-0.025" } -# moving client keybind - - key { mod = {"Control","Alt"} key = "Left" func = "keymovex" cmd = "-10" } - key { mod = {"Control","Alt"} key = "Right" func = "keymovex" cmd = "+10" } - key { mod = {"Control","Alt"} key = "Up" func = "keymovey" cmd = "-10" } - key { mod = {"Control","Alt"} key = "Down" func = "keymovey" cmd = "+10" } - -# resize client keybind - - key { mod = {"Shift","Alt"} key = "Down" func = "keyresize" cmd = "+h" } - key { mod = {"Shift","Alt"} key = "Right" func = "keyresize" cmd = "+w" } - key { mod = {"Shift","Alt"} key = "Up" func = "keyresize" cmd = "-h" } - key { mod = {"Shift","Alt"} key = "Left" func = "keyresize" cmd = "-w" } - # tag manipulation keybind + key { mod = {"Alt"} key = "F1" func = "tag" cmd = "1" } + key { mod = {"Alt"} key = "F2" func = "tag" cmd = "2" } + key { mod = {"Alt"} key = "F3" func = "tag" cmd = "3" } + key { mod = {"Alt"} key = "F4" func = "tag" cmd = "4" } + key { mod = {"Alt"} key = "F5" func = "tag" cmd = "5" } + key { mod = {"Alt"} key = "F6" func = "tag" cmd = "6" } + key { mod = {"Alt"} key = "F7" func = "tag" cmd = "7" } + key { mod = {"Alt"} key = "F8" func = "tag" cmd = "8" } + key { mod = {"Alt"} key = "F9" func = "tag" cmd = "9" } - key { mod = {"Alt"} key = "F1" func = "tag" cmd = "1" } - key { mod = {"Alt"} key = "F2" func = "tag" cmd = "2" } - key { mod = {"Alt"} key = "F3" func = "tag" cmd = "3" } - key { mod = {"Alt"} key = "F4" func = "tag" cmd = "4" } - key { mod = {"Alt"} key = "F5" func = "tag" cmd = "5" } - key { mod = {"Alt"} key = "F6" func = "tag" cmd = "6" } - key { mod = {"Alt"} key = "F7" func = "tag" cmd = "7" } - key { mod = {"Alt"} key = "F8" func = "tag" cmd = "8" } - key { mod = {"Alt"} key = "F9" func = "tag" cmd = "9" } - - key { mod = {"Control", "Shift"} key = "F1" func = "tagtransfert" cmd ="1" } - key { mod = {"Control", "Shift"} key = "F2" func = "tagtransfert" cmd ="2" } - key { mod = {"Control", "Shift"} key = "F3" func = "tagtransfert" cmd ="3" } - key { mod = {"Control", "Shift"} key = "F4" func = "tagtransfert" cmd ="4" } - key { mod = {"Control", "Shift"} key = "F5" func = "tagtransfert" cmd ="5" } - key { mod = {"Control", "Shift"} key = "F6" func = "tagtransfert" cmd ="6" } - key { mod = {"Control", "Shift"} key = "F7" func = "tagtransfert" cmd ="7" } - key { mod = {"Control", "Shift"} key = "F8" func = "tagtransfert" cmd ="8" } - key { mod = {"Control", "Shift"} key = "F9" func = "tagtransfert" cmd ="9" } - + key { mod = {"Control", "Shift"} key = "F1" func = "tagtransfert" cmd ="1" } + key { mod = {"Control", "Shift"} key = "F2" func = "tagtransfert" cmd ="2" } + key { mod = {"Control", "Shift"} key = "F3" func = "tagtransfert" cmd ="3" } + key { mod = {"Control", "Shift"} key = "F4" func = "tagtransfert" cmd ="4" } + key { mod = {"Control", "Shift"} key = "F5" func = "tagtransfert" cmd ="5" } + key { mod = {"Control", "Shift"} key = "F6" func = "tagtransfert" cmd ="6" } + key { mod = {"Control", "Shift"} key = "F7" func = "tagtransfert" cmd ="7" } + key { mod = {"Control", "Shift"} key = "F8" func = "tagtransfert" cmd ="8" } + key { mod = {"Control", "Shift"} key = "F9" func = "tagtransfert" cmd ="9" } }