...
 
Commits (2)
...@@ -78,7 +78,6 @@ static void updatemon(struct monitor *, int, int, unsigned int, unsigned int); ...@@ -78,7 +78,6 @@ static void updatemon(struct monitor *, int, int, unsigned int, unsigned int);
static void updatetransient(struct client *); static void updatetransient(struct client *);
static void updatewsm(void); static void updatewsm(void);
static void updatewsmbox(struct workspace *); static void updatewsmbox(struct workspace *);
static void viewmon(struct monitor *);
static int xerror(Display *, XErrorEvent *); static int xerror(Display *, XErrorEvent *);
static int (*xerrorxlib)(Display *, XErrorEvent *); static int (*xerrorxlib)(Display *, XErrorEvent *);
...@@ -629,67 +628,104 @@ void ...@@ -629,67 +628,104 @@ void
movemouse(union arg arg) movemouse(union arg arg)
{ {
struct monitor *mon; struct monitor *mon;
struct workspace *ws;
struct client *c;
Window root_win, child_win;
int root_x, root_y, child_x, child_y, dx, dy;
struct position newpos;
int unsigned modmask;
Bool ret;
XEvent ev; XEvent ev;
Window dummy;
struct client *c = seat->selmon->selws->selcli;
int cx = c->dim.x, cy = c->dim.y, x, y, i;
unsigned int ui;
(void) arg; (void) arg;
debug("movemouse(%lu)", c->win); debug("movemouse()");
/* initial sanity check */
if (!seat->selmon
|| !seat->selmon->selws
|| !seat->selmon->selws->selcli) {
debug("No focused client");
return;
}
mon = seat->selmon;
ws = mon->selws;
c = ws->selcli;
/* don't move fullscreen client */ /* don't move fullscreen client */
if (c->fullscreen) { if (c->fullscreen) {
debug("Fullscreen client, not moving");
return; return;
} }
/* float if not floating yet */ /* get pointer information */
if (!c->floating) ret = XQueryPointer(x11.dpy, x11.root, &root_win, &child_win,
togglefloat((union arg) { .i = 0 }); &root_x, &root_y, &child_x, &child_y, &modmask);
else if (ret == False) {
XRaiseWindow(x11.dpy, c->win); warn("XQueryPointer failed");
return;
}
if (root_win != x11.root) {
warn("XQueryPointer returned different root %lu (expected %lu)",
root_win, x11.root);
return;
}
if (child_win != c->win) {
warn("XQueryPointer returned different window %lu (expected %lu)",
child_win, c->win);
return;
}
/* float, move under cursor, and raise */
if (!c->floating) {
setfloating(c, true);
newpos.x = root_x
- (int signed) (c->dim.width / 2 + c->border.width);
newpos.y = root_y
- (int signed) (c->dim.height / 2 + c->border.width);
client_move(c, newpos);
}
workspace_raise_floating(ws, c);
monitor_restack(mon);
/* grab the pointer and change the cursor appearance */ /* grab the pointer and change the cursor appearance */
if (XGrabPointer(x11.dpy, x11.root, true, MOUSEMASK, if (XGrabPointer(x11.dpy, x11.root, true, MOUSEMASK,
GrabModeAsync, GrabModeAsync, None, cursor[CurMove], GrabModeAsync, GrabModeAsync, None, cursor[CurMove],
CurrentTime) != GrabSuccess) { CurrentTime) != GrabSuccess) {
warn("XGrabPointer() failed"); warn("XGrabPointer failed");
return;
}
/* get initial pointer position */
if (!XQueryPointer(x11.dpy, x11.root, &dummy, &dummy, &x, &y, &i, &i, &ui)) {
warn("XQueryPointer() failed");
return; return;
} }
/* handle motions */ /* handle motions */
do { do {
XMaskEvent(x11.dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); XMaskEvent(x11.dpy,
MOUSEMASK|ExposureMask|SubstructureRedirectMask,
&ev);
switch (ev.type) { switch (ev.type) {
case ConfigureRequest: case ConfigureRequest:
case Expose: case Expose:
case MapRequest: case MapRequest:
handle[ev.type](&ev); handle[ev.type](&ev);
break; break;
case MotionNotify: case MotionNotify:
cx = cx+(ev.xmotion.x-x); dx = ev.xmotion.x_root - root_x;
cy = cy+(ev.xmotion.y-y); dy = ev.xmotion.y_root - root_y;
x = ev.xmotion.x; root_x = ev.xmotion.x_root;
y = ev.xmotion.y; root_y = ev.xmotion.y_root;
client_move(c, (struct position) { cx, cy }); newpos.x = c->dim.x + dx;
break; newpos.y = c->dim.y + dy;
client_move(c, newpos);
break;
} }
} while (ev.type != ButtonRelease); } while (ev.type != ButtonRelease);
/* check if it has been moved to another monitor */ /* check if it has been moved to another monitor */
mon = locaterect(&c->dim.pos, &c->dim.size); mon = locaterect(&c->dim.pos, &c->dim.size);
if (mon != seat->selmon) { if (mon != seat->selmon) {
debug("Client has changed monitor, transferring");
workspace_detach_client(c->ws, c); workspace_detach_client(c->ws, c);
workspace_attach_client(mon->selws, c); workspace_attach_client(mon->selws, c);
viewmon(mon); seat_focus_monitor(seat, mon);
updatefocus();
} }
XUngrabPointer(x11.dpy, CurrentTime); XUngrabPointer(x11.dpy, CurrentTime);
...@@ -1880,16 +1916,6 @@ updatewsmbox(struct workspace *ws) ...@@ -1880,16 +1916,6 @@ updatewsmbox(struct workspace *ws)
XMoveWindow(x11.dpy, ws->wsmbox->window, x, y); XMoveWindow(x11.dpy, ws->wsmbox->window, x, y);
} }
void
viewmon(struct monitor *mon)
{
struct monitor *oldmon = seat->selmon;
seat->selmon = mon;
if (oldmon)
monitor_focus(oldmon, false);
monitor_focus(mon, true);
}
void void
viewws(union arg arg) viewws(union arg arg)
{ {
......
...@@ -183,7 +183,7 @@ workspace_set_floating(struct workspace *ws, struct client *c, bool floating) ...@@ -183,7 +183,7 @@ workspace_set_floating(struct workspace *ws, struct client *c, bool floating)
list_remove(src, c, NULL); list_remove(src, c, NULL);
c->floating = floating; c->floating = floating;
if (ws->selcli == c) if (dst == ws->floating)
list_prepend(dst, c); list_prepend(dst, c);
else else
list_append(dst, c); list_append(dst, c);
......