From 29e5b7a213ee46312e633fe95ea02a7050aff625 Mon Sep 17 00:00:00 2001 From: moetunes Date: Thu, 24 Nov 2011 12:46:24 +1000 Subject: Unified master and stack resizing functions as per c00kiemon5ter --- src/.gitignore | 1 + src/config.h.def | 14 +++++++------- src/dminiwm.c | 42 +++++++++++++++--------------------------- 3 files changed, 23 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/.gitignore b/src/.gitignore index ea4fa17..7f9cf82 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,4 +1,5 @@ dminiwm +config.h *.o *.swp *~ diff --git a/src/config.h.def b/src/config.h.def index 19f656b..fed94d4 100644 --- a/src/config.h.def +++ b/src/config.h.def @@ -1,6 +1,6 @@ - /* config.h for dminiwm.c [ 0.1.6 ] + /* config.h for dminiwm.c [ 0.1.7 ] * - * Started from catwm 31/12/10 + * Started from catwm 31/12/10 * Bad window error checking and numlock checking used from * 2wm at http://hg.suckless.org/2wm/ * @@ -26,7 +26,7 @@ /* Mod (Mod1 == alt) (Mod4 == Super/windows) */ #define MOD1 Mod1Mask -#define MOD4 Mod4Mask +#define MOD4 Mod4Mask #define MASTER_SIZE 0.52 #define TOP_PANEL 1 /* 1=Don't 0=Have the panel at the top instead of the bottom */ #define PANEL_HEIGHT 18 /* 0 for no space for a panel */ @@ -77,14 +77,14 @@ const char* shutdowncmd[] = {"sudo","shutdown","-h","now",NULL}; // Shortcuts static key keys[] = { // MOD KEY FUNCTION ARGS - { MOD1, XK_h, increase, {NULL}}, - { MOD1, XK_l, decrease, {NULL}}, + { MOD1, XK_h, resize_master, {.i = 10}}, + { MOD1, XK_l, resize_master, {.i = -10}}, { MOD1, XK_c, kill_client, {NULL}}, { MOD1, XK_j, next_win, {NULL}}, { MOD1, XK_k, prev_win, {NULL}}, { MOD1, XK_v, spawn, {.com = dmenucmd}}, - { MOD1, XK_p, grow_window, {NULL}}, - { MOD1, XK_o, shrink_window, {NULL}}, + { MOD1, XK_p, resize_stack, {.i = 10}}, + { MOD1, XK_o, resize_stack, {.i = -10}}, { MOD1, XK_Return, spawn, {.com = urxvtcmd}}, { MOD1, XK_Up, spawn, {.com = volupcmd}}, { MOD1, XK_Down, spawn, {.com = voldowncmd}}, diff --git a/src/dminiwm.c b/src/dminiwm.c index 2c4915e..1c1b0ff 100644 --- a/src/dminiwm.c +++ b/src/dminiwm.c @@ -1,6 +1,6 @@ -/* dminiwm.c [ 0.1.6 ] +/* dminiwm.c [ 0.1.7 ] * -* I started this from catwm 31/12/10 +* I started this from catwm 31/12/10 * Bad window error checking and numlock checking used from * 2wm at http://hg.suckless.org/2wm/ * @@ -101,14 +101,11 @@ static void change_desktop(const Arg arg); static void client_to_desktop(const Arg arg); static void configurenotify(XEvent *e); static void configurerequest(XEvent *e); -static void decrease(); static void destroynotify(XEvent *e); static void enternotify(XEvent *e); static void logger(const char* e); static unsigned long getcolor(const char* color); static void grabkeys(); -static void grow_window(); -static void increase(); static void keypress(XEvent *e); static void kill_client(); static void maprequest(XEvent *e); @@ -120,11 +117,12 @@ static void prev_desktop(); static void prev_win(); static void quit(); static void remove_window(Window w); +static void resize_master(const Arg arg); +static void resize_stack(const Arg arg); static void save_desktop(int i); static void select_desktop(int i); static void send_kill_signal(Window w); static void setup(); -static void shrink_window(); static void sigchld(int unused); static void spawn(const Arg arg); static void start(); @@ -189,7 +187,7 @@ void add_window(Window w) { else { if(ATTACH_ASIDE == 0) { for(t=head;t->next;t=t->next); - + c->next = NULL; c->prev = t; c->win = w; @@ -350,16 +348,6 @@ void swap_master() { } } -void decrease() { - master_size -= 10; - tile(); -} - -void increase() { - master_size += 10; - tile(); -} - /* **************************** Desktop Management ************************************* */ void change_desktop(const Arg arg) { client *c; @@ -522,7 +510,7 @@ void tile() { wdt = sw - BORDER_WIDTH; if((n == x) && (n == 8)) wdt = 2*sw/3 - BORDER_WIDTH; - } else + } else if(x >= 5) { wdt = (sw/3) - BORDER_WIDTH; ht = (sh/2) - BORDER_WIDTH; @@ -625,13 +613,13 @@ void switch_grid() { } } -void grow_window() { - growth += 10; - tile(); +void resize_master(const Arg arg) { + master_size += arg.i; + tile(); } -void shrink_window() { - growth -= 10; +void resize_stack(const Arg arg) { + growth += arg.i; tile(); } @@ -817,7 +805,7 @@ void enternotify(XEvent *e) { } } -void send_kill_signal(Window w) { +void send_kill_signal(Window w) { XEvent ke; ke.type = ClientMessage; ke.xclient.window = w; @@ -843,7 +831,7 @@ void quit() { Window root_return, parent; Window *children; int i; - unsigned int nchildren; + unsigned int nchildren; XEvent ev; /* @@ -881,7 +869,7 @@ void quit() { void logger(const char* e) { fprintf(stdout,"\n\033[0;34m:: dminiwm : %s \033[0;m\n", e); } - + void setup() { // Install a signal sigchld(0); @@ -1004,7 +992,7 @@ void start() { int main(int argc, char **argv) { - // Open display + // Open display if(!(dis = XOpenDisplay(NULL))) { logger("\033[0;31mCannot open display!"); exit(1); -- cgit v1.3.1 From 544de8a8e3d2940043b982454fa80340a7461f21 Mon Sep 17 00:00:00 2001 From: moetunes Date: Thu, 24 Nov 2011 17:31:31 +1000 Subject: Edit README --- src/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/README b/src/README index b86a106..1580a73 100644 --- a/src/README +++ b/src/README @@ -99,5 +99,5 @@ Need Xlib, then: ###Todo ---- - * I'll think of something + * when swithching desktops stop the mouse being in an unfocused window changing focus. -- cgit v1.3.1 From c7890dd59f6e0c9cd58bf30ba3ca290f392fa8c8 Mon Sep 17 00:00:00 2001 From: moetunes Date: Sat, 26 Nov 2011 10:10:52 +1000 Subject: Added a click to focus option --- src/ChangeLog | 3 +++ src/Makefile | 2 +- src/README | 8 ++++---- src/config.h.def | 3 ++- src/dminiwm.c | 25 +++++++++++++++++++++++-- 5 files changed, 33 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index c960952..f3a549b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,6 @@ +26/11/11 + Added option to click on a window to focus it + 21/11/11 Fix for transient windows not being managed diff --git a/src/Makefile b/src/Makefile index 55332f9..0316713 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,7 +11,7 @@ CC=gcc all: $(EXEC) dminiwm: dminiwm.o - $(CC) $(LDFLAGS) -Os -o $@ $+ $(LDADD) + $(CC) $(LDFLAGS) -s -Os -o $@ $+ $(LDADD) install: all install -Dm 755 dminiwm $(DESTDIR)$(BINDIR)/dminiwm diff --git a/src/README b/src/README index 1580a73..cbe4084 100644 --- a/src/README +++ b/src/README @@ -12,7 +12,7 @@ Screenshots and ramblings/updates at https://bbs.archlinux.org/viewtopic.php?id= **dminiwm** is a very minimal and lightweight dynamic tiling window manager. I will try to stay under 1000 SLOC. - Currently under 900 lines with the config file included. + Currently under 950 lines with the config file included. ###Modes @@ -60,9 +60,8 @@ It allows the "normal" method of tiling window managers(with the new window as t ###Recent Changes -------------- -15/10/11 - Added having applications open on specified desktop - +26/11/11 + Added a click to focus option ###Status ------ @@ -76,6 +75,7 @@ There are more options in the config file than the original catwm. * Fixed a window being destroyed on another desktop creating ghost windows. * Added ability to resize the window on the top of the stack * Added having applications open on specified desktop + * Added a click to focus option ###Installation diff --git a/src/config.h.def b/src/config.h.def index fed94d4..e50253e 100644 --- a/src/config.h.def +++ b/src/config.h.def @@ -1,4 +1,4 @@ - /* config.h for dminiwm.c [ 0.1.7 ] + /* config.h for dminiwm.c [ 0.1.8 ] * * Started from catwm 31/12/10 * Bad window error checking and numlock checking used from @@ -35,6 +35,7 @@ #define DEFAULT_MODE 0 /* 0=Vertical, 1=Fullscreen 2=Horizontal 3=grid*/ #define FOLLOW_MOUSE 0 /* 1=Don't 0=Focus the window the mouse just entered */ #define FOLLOW_WINDOW 0 /* 1=Don't 0=Follow the window when moved to a different desktop */ +#define CLICK_TO_FOCUS 0 /* 1=Don't 0=Focus an unfocused window when clicked */ #define DESKTOPS 6 /* Must edit DESKTOPCHANGE keys to suit */ // Colors diff --git a/src/dminiwm.c b/src/dminiwm.c index 1c1b0ff..d25f05b 100644 --- a/src/dminiwm.c +++ b/src/dminiwm.c @@ -1,4 +1,4 @@ -/* dminiwm.c [ 0.1.7 ] +/* dminiwm.c [ 0.1.8 ] * * I started this from catwm 31/12/10 * Bad window error checking and numlock checking used from @@ -97,6 +97,7 @@ static const AtomNode atomList[] = { // Functions static void add_window(Window w); +static void buttonpressed(XEvent *e); static void change_desktop(const Arg arg); static void client_to_desktop(const Arg arg); static void configurenotify(XEvent *e); @@ -161,6 +162,7 @@ static void (*events[LASTEvent])(XEvent *e) = { [KeyPress] = keypress, [MapRequest] = maprequest, [EnterNotify] = enternotify, + [ButtonPress] = buttonpressed, [DestroyNotify] = destroynotify, [ConfigureNotify] = configurenotify, [ConfigureRequest] = configurerequest @@ -571,9 +573,14 @@ void update_current() { XSetWindowBorder(dis,c->win,win_focus); XSetInputFocus(dis,c->win,RevertToParent,CurrentTime); XRaiseWindow(dis,c->win); + if(CLICK_TO_FOCUS == 0) + XUngrabButton(dis, AnyButton, AnyModifier, c->win); } - else + else { XSetWindowBorder(dis,c->win,win_unfocus); + if(CLICK_TO_FOCUS == 0) + XGrabButton(dis, AnyButton, AnyModifier, c->win, True, ButtonPressMask|ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None); + } } XSync(dis, False); } @@ -805,6 +812,20 @@ void enternotify(XEvent *e) { } } +void buttonpressed(XEvent *e) { + client *c; + XButtonPressedEvent *ev = &e->xbutton; + + // change focus with LMB + if(CLICK_TO_FOCUS == 0 && ev->window != current->win && ev->button == Button1) + for(c=head;c;c=c->next) + if(ev->window == c->win) { + current = c; + update_current(); + return; + } +} + void send_kill_signal(Window w) { XEvent ke; ke.type = ClientMessage; -- cgit v1.3.1 From c6e3b1e20bf92cbaab05a3075a3f7a78b14ad113 Mon Sep 17 00:00:00 2001 From: moetunes Date: Sat, 26 Nov 2011 10:18:30 +1000 Subject: README edit --- src/README | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/README b/src/README index cbe4084..b835d87 100644 --- a/src/README +++ b/src/README @@ -83,7 +83,8 @@ There are more options in the config file than the original catwm. Need Xlib, then: - edit the config.h file to suit your needs + edit the config.h.def file to suit your needs + and save it as config.h. $ make # make install -- cgit v1.3.1