diff --git a/config.def.h b/config.def.h index cae2009..80e9f59 100644 --- a/config.def.h +++ b/config.def.h @@ -2,6 +2,8 @@ #define CONFIG_H #define MOD Mod4Mask +#define BORDER_COLOR "#00FF00" +#define BORDER_WIDTH 1 const char* menu[] = {"dmenu_run", 0}; const char* term[] = {"st", 0}; @@ -18,6 +20,21 @@ static struct key keys[] = { {MOD, XK_c, win_center, {0}}, {MOD, XK_f, win_fs, {0}}, + {MOD, XK_k, win_move, {.com = (const char*[]){"move", "n"}, .i = 10}}, + {MOD, XK_j, win_move, {.com = (const char*[]){"move", "s"}, .i = 10}}, + {MOD, XK_l, win_move, {.com = (const char*[]){"move", "e"}, .i = 10}}, + {MOD, XK_h, win_move, {.com = (const char*[]){"move", "w"}, .i = 10}}, + + {MOD|ShiftMask, XK_k, win_move, {.com = (const char*[]){"resize", "n"}, .i = 10}}, + {MOD|ShiftMask, XK_j, win_move, {.com = (const char*[]){"resize", "s"}, .i = 10}}, + {MOD|ShiftMask, XK_l, win_move, {.com = (const char*[]){"resize", "e"}, .i = 10}}, + {MOD|ShiftMask, XK_h, win_move, {.com = (const char*[]){"resize", "w"}, .i = 10}}, + + {MOD|Mod1Mask, XK_k, win_half, {.com = (const char*[]){"n"}}}, + {MOD|Mod1Mask, XK_j, win_half, {.com = (const char*[]){"s"}}}, + {MOD|Mod1Mask, XK_l, win_half, {.com = (const char*[]){"e"}}}, + {MOD|Mod1Mask, XK_h, win_half, {.com = (const char*[]){"w"}}}, + {Mod1Mask, XK_Tab, win_next, {0}}, {Mod1Mask|ShiftMask, XK_Tab, win_prev, {0}}, diff --git a/sowm.c b/sowm.c index 96f8340..7c3edca 100644 --- a/sowm.c +++ b/sowm.c @@ -7,13 +7,15 @@ #include #include #include +#include #include "sowm.h" -static client *list = {0}, *ws_list[10] = {0}, *cur; +static client *list = {0}, *ws_list[NUM_WS] = {0}, *cur; static int ws = 1, sw, sh, wx, wy, numlock = 0; static unsigned int ww, wh; +static int s; static Display *d; static XButtonEvent mouse; static Window root; @@ -32,6 +34,37 @@ static void (*events[LASTEvent])(XEvent *e) = { #include "config.h" +unsigned long getcolor(const char *col) { + Colormap m = DefaultColormap(d, s); + XColor c; + return (!XAllocNamedColor(d, m, col, &c, &c))?0:c.pixel; +} + +void win_move(const Arg arg) { + int r = arg.com[0][0] == 'r'; + char m = arg.com[1][0]; + + win_size(cur->w, &wx, &wy, &ww, &wh); + + XMoveResizeWindow(d, cur->w, \ + wx + (r ? 0 : m == 'e' ? arg.i : m == 'w' ? -arg.i : 0), + wy + (r ? 0 : m == 'n' ? -arg.i : m == 's' ? arg.i : 0), + MAX(10, ww + (r ? m == 'e' ? arg.i : m == 'w' ? -arg.i : 0 : 0)), + MAX(10, wh + (r ? m == 'n' ? -arg.i : m == 's' ? arg.i : 0 : 0))); +} + +void win_half(const Arg arg) { + char m = arg.com[0][0]; + + win_size(cur->w, &wx, &wy, &ww, &wh); + + XMoveResizeWindow(d, cur->w, \ + (m == 'w' ? wx : m == 'e' ? (wx + ww / 2) : wx), + (m == 'n' ? wy : m == 's' ? (wy + wh / 2) : wy), + (m == 'w' ? (ww / 2) : m == 'e' ? (ww / 2) : ww), + (m == 'n' ? (wh / 2) : m == 's' ? (wh / 2) : wh)); +} + void win_focus(client *c) { cur = c; XSetInputFocus(d, cur->w, RevertToParent, CurrentTime); @@ -45,6 +78,7 @@ void notify_destroy(XEvent *e) { void notify_enter(XEvent *e) { while(XCheckTypedEvent(d, EnterNotify, e)); + while(XCheckTypedWindowEvent(d, mouse.subwindow, MotionNotify, e)); for win if (c->w == e->xcrossing.window) win_focus(c); } @@ -208,13 +242,30 @@ void configure_request(XEvent *e) { }); } +bool exists_win(Window w) { + int tmp = ws; + for (int i = 0; i < NUM_WS; ++i) { + if (i == tmp) continue; + ws_sel(i); + for win if (c->w == w) { + ws_sel(tmp); + return true; + } + } + ws_sel(tmp); + return false; +} + void map_request(XEvent *e) { Window w = e->xmaprequest.window; + if(exists_win(w)) return; XSelectInput(d, w, StructureNotifyMask|EnterWindowMask); win_size(w, &wx, &wy, &ww, &wh); win_add(w); cur = list->prev; + XSetWindowBorder(d, w, getcolor(BORDER_COLOR)); + XConfigureWindow(d, w, CWBorderWidth, &(XWindowChanges){.border_width = BORDER_WIDTH}); if (wx + wy == 0) win_center((Arg){0}); @@ -277,8 +328,8 @@ int main(void) { int s = DefaultScreen(d); root = RootWindow(d, s); - sw = XDisplayWidth(d, s); - sh = XDisplayHeight(d, s); + sw = XDisplayWidth(d, s) - (2*BORDER_WIDTH); + sh = XDisplayHeight(d, s) - (2*BORDER_WIDTH); XSelectInput(d, root, SubstructureRedirectMask); XDefineCursor(d, root, XCreateFontCursor(d, 68)); diff --git a/sowm.h b/sowm.h index b059f06..01b4929 100644 --- a/sowm.h +++ b/sowm.h @@ -1,5 +1,7 @@ #include +#define NUM_WS 10 + #define win (client *t=0, *c=list; c && t!=list->prev; t=c, c=c->next) #define ws_save(W) ws_list[W] = list #define ws_sel(W) list = ws_list[ws = W] @@ -33,6 +35,7 @@ typedef struct client { Window w; } client; +unsigned long getcolor(const char *col); void button_press(XEvent *e); void button_release(XEvent *e); void configure_request(XEvent *e); @@ -52,7 +55,10 @@ void win_focus(client *c); void win_kill(const Arg arg); void win_prev(const Arg arg); void win_next(const Arg arg); +void win_move(const Arg arg); +void win_half(const Arg arg); void win_to_ws(const Arg arg); void ws_go(const Arg arg); +bool exists_win(Window w); static int xerror() { return 0; }