Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Last focused window is focused and mouse moved to it on window remova…

…l or desktop change
  • Loading branch information...
commit 78a6d16ebf6a46cf132c04353645d8609b4fba47 1 parent 19d45eb
moetunes authored

Showing 3 changed files with 38 additions and 7 deletions. Show diff stats Hide diff stats

  1. +4 0 ChangeLog
  2. +4 2 README.md
  3. +30 5 dminiwm.c
4 ChangeLog
... ... @@ -1,3 +1,7 @@
  1 +27/2/12
  2 + If FOLLOW_MOUSE = 0 the cursor will be moved to the last focused window
  3 + when a window is removed or the desktop changed
  4 +
1 5 26/2/12
2 6 Added option to config to not have the panel shown if there's a window open
3 7
6 README.md
Source Rendered
@@ -62,9 +62,10 @@ It allows the "normal" method of tiling window managers(with the new window as t
62 62 ###Recent Changes
63 63 --------------
64 64
65   -6/2/12
  65 +27/2/12
66 66
67   -> Transient windows are now always floating and always on top
  67 +> Option in the config file to not show a panel when a window is open.
  68 + Last focused window is refocused and the mouse moved to it on window removal or desktop change
68 69
69 70 ###Status
70 71 ------
@@ -80,6 +81,7 @@ There are more options in the config file than the original catwm.
80 81 * Added having applications open on specified desktop
81 82 * Added a click to focus option
82 83 * Added ability to change back to last opened desktop.
  84 + * Transient windows are now always floating and always on top
83 85
84 86
85 87 ###Installation
35 dminiwm.c
@@ -54,7 +54,7 @@ struct client{
54 54 // Prev and next client
55 55 client *next;
56 56 client *prev;
57   -
  57 + client *prev_current;
58 58 // The window
59 59 Window win;
60 60 };
@@ -113,6 +113,7 @@ static void tile();
113 113 static void toggle_panel();
114 114 static void unmapnotify(XEvent *e); // Thunderbird's write window just unmaps...
115 115 static void update_current();
  116 +static void warp_pointer();
116 117
117 118 // Include configuration file (need struct key)
118 119 #include "config.h"
@@ -138,6 +139,7 @@ static Window root;
138 139 static client *head;
139 140 static client *current;
140 141 static client *transient;
  142 +static XWindowAttributes attr;
141 143
142 144 // Events array
143 145 static void (*events[LASTEvent])(XEvent *e) = {
@@ -178,9 +180,10 @@ void add_window(Window w, int tw) {
178 180 }
179 181 else {
180 182 if(ATTACH_ASIDE == 0) {
181   - for(t=head;t->next;t=t->next);
  183 + for(t=head;t->next;t=t->next); // Start at the last in the stack
182 184 c->next = NULL;
183 185 c->prev = t;
  186 + c->prev_current = current;
184 187 c->win = w;
185 188 t->next = c;
186 189 }
@@ -188,6 +191,7 @@ void add_window(Window w, int tw) {
188 191 t=head;
189 192 c->prev = NULL;
190 193 c->next = t;
  194 + c->prev_current = current;
191 195 c->win = w;
192 196 t->prev = c;
193 197 head = c;
@@ -230,19 +234,24 @@ void remove_window(Window w, int dr) {
230 234 return;
231 235 }
232 236
  237 + if(desktops[current_desktop].numwins < 3)
  238 + c->prev_current = NULL;
233 239 if(c->prev == NULL) {
234 240 head = c->next;
235 241 c->next->prev = NULL;
236   - current = c->next;
  242 + if(c->prev_current == NULL) current = c->next;
  243 + else current = c->prev_current;
237 244 }
238 245 else if(c->next == NULL) {
239 246 c->prev->next = NULL;
240   - current = c->prev;
  247 + if(c->prev_current == NULL) current = c->prev;
  248 + else current = c->prev_current;
241 249 }
242 250 else {
243 251 c->prev->next = c->next;
244 252 c->next->prev = c->prev;
245   - current = c->prev;
  253 + current = c->prev_current;
  254 + //current = c->prev;
246 255 }
247 256
248 257 if(dr == 0) free(c);
@@ -251,6 +260,7 @@ void remove_window(Window w, int dr) {
251 260 save_desktop(current_desktop);
252 261 tile();
253 262 update_current();
  263 + if(desktops[current_desktop].numwins > 1) warp_pointer();
254 264 return;
255 265 }
256 266 }
@@ -265,10 +275,12 @@ void next_win() {
265 275 else
266 276 c = current->next;
267 277
  278 + c->prev_current = current;
268 279 current = c;
269 280 if(mode == 1)
270 281 tile();
271 282 update_current();
  283 + warp_pointer();
272 284 }
273 285 }
274 286
@@ -281,10 +293,12 @@ void prev_win() {
281 293 else
282 294 c = current->prev;
283 295
  296 + c->prev_current = current;
284 297 current = c;
285 298 if(mode == 1)
286 299 tile();
287 300 update_current();
  301 + warp_pointer();
288 302 }
289 303 }
290 304
@@ -367,6 +381,7 @@ void change_desktop(const Arg arg) {
367 381
368 382 tile();
369 383 update_current();
  384 + warp_pointer();
370 385 }
371 386
372 387 void last_desktop() {
@@ -683,6 +698,14 @@ void keypress(XEvent *e) {
683 698 }
684 699 }
685 700
  701 +void warp_pointer() {
  702 + // Move cursor to the center of the current window
  703 + if(FOLLOW_MOUSE == 0 && head != NULL) {
  704 + XGetWindowAttributes(dis, current->win, &attr);
  705 + XWarpPointer(dis, None, current->win, 0, 0, 0, 0, attr.width/2, attr.height/2);
  706 + }
  707 +}
  708 +
686 709 void configurenotify(XEvent *e) {
687 710 // Do nothing for the moment
688 711 }
@@ -773,6 +796,7 @@ void maprequest(XEvent *e) {
773 796 XMapWindow(dis,ev->window);
774 797 tile();
775 798 update_current();
  799 + warp_pointer();
776 800 }
777 801
778 802 void destroynotify(XEvent *e) {
@@ -808,6 +832,7 @@ void enternotify(XEvent *e) {
808 832 if(transient != NULL) return;
809 833 for(c=head;c;c=c->next)
810 834 if(ev->window == c->win) {
  835 + c->prev_current = current;
811 836 current = c;
812 837 update_current();
813 838 return;

0 comments on commit 78a6d16

Please sign in to comment.
Something went wrong with that request. Please try again.