diff --git a/src/client.c b/src/client.c index 067a444..2465871 100644 --- a/src/client.c +++ b/src/client.c @@ -664,6 +664,38 @@ client_size_hints(Client *c) return; } +/** Swap two clients + *\param 1 c1 First client + *\param 2 c2 Second client +*/ +void +client_swap(Client *c1, Client *c2) +{ + /* Swap juste the window */ + swap_ptr((void**)&c1->win, (void**)&c2->win); + swap_ptr((void**)&c1->title, (void**)&c2->title); + + /* Re-adapt the window position with its new frame */ + XReparentWindow(dpy, c1->win, c1->frame, BORDH, TBARH); + XReparentWindow(dpy, c2->win, c2->frame, BORDH, TBARH); + + /* Resize the window */ + XResizeWindow(dpy, c1->win, c2->geo.width, c2->geo.height); + XResizeWindow(dpy, c2->win, c1->geo.width, c1->geo.height); + + /* Re-get the client size hints */ + client_size_hints(c1); + client_size_hints(c2); + + + /* Arrange */ + arrange(c1->screen); + if(c1->screen != c2->screen) + arrange(c2->screen); + + return; +} + /** Set the wanted tag of a client *\param c Client pointer */ diff --git a/src/mouse.c b/src/mouse.c index f8c8e46..3505239 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -57,7 +57,7 @@ mouse_move(Client *c) uint duint; Window dw, sw; Client *sclient; - XRectangle geo = c->geo, ogeo; + XRectangle geo = c->geo; XGCValues xgc; GC gci; XEvent ev; @@ -101,9 +101,11 @@ mouse_move(Client *c) || (sclient = client_gb_frame(sw)) || (sclient = client_gb_titlebar(sw))) { - ogeo = c->geo; - client_moveresize(c, sclient->geo, False); - client_moveresize(sclient, ogeo, False); + if(c != sclient) + { + client_swap(c, sclient); + break; + } } /* To move a client from one tag to another */ diff --git a/src/util.c b/src/util.c index 0a82e82..2356fa2 100644 --- a/src/util.c +++ b/src/util.c @@ -236,6 +236,21 @@ spawn(const char *format, ...) return; } +/** Swap two pointer. + *\param x First pointer + *\param y Second pointer +*/ +void +swap_ptr(void **x, void **y) +{ + void *t = *x; + + *x = *y; + *y = t; + + return; +} + /** Execute a sh command * \param cmd Command (uicb_t type) */ diff --git a/src/wmfs.h b/src/wmfs.h index a825d8a..69e53bd 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -145,6 +145,7 @@ Client* client_manage(Window w, XWindowAttributes *wa, Bool ar); void client_moveresize(Client *c, XRectangle geo, Bool r); void client_maximize(Client *c); void client_size_hints(Client *c); +void client_swap(Client *c1, Client *c2); void client_raise(Client *c); void client_unhide(Client *c); void client_unmanage(Client *c); @@ -238,6 +239,7 @@ char* alias_to_str(char *conf_choice); /* }}} */ XRectangle get_mouse_pos(void); void spawn(const char *str, ...); +void swap_ptr(void **x, void **y); void uicb_spawn(uicb_t); /* tag.c */