...
 
Commits (2)
......@@ -78,7 +78,6 @@ static void updatemon(struct monitor *, int, int, unsigned int, unsigned int);
static void updatetransient(struct client *);
static void updatewsm(void);
static void updatewsmbox(struct workspace *);
static void viewmon(struct monitor *);
static int xerror(Display *, XErrorEvent *);
static int (*xerrorxlib)(Display *, XErrorEvent *);
......@@ -629,44 +628,79 @@ void
movemouse(union arg arg)
{
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;
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;
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 */
if (c->fullscreen) {
debug("Fullscreen client, not moving");
return;
}
/* float if not floating yet */
if (!c->floating)
togglefloat((union arg) { .i = 0 });
else
XRaiseWindow(x11.dpy, c->win);
/* get pointer information */
ret = XQueryPointer(x11.dpy, x11.root, &root_win, &child_win,
&root_x, &root_y, &child_x, &child_y, &modmask);
if (ret == False) {
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 */
if (XGrabPointer(x11.dpy, x11.root, true, MOUSEMASK,
GrabModeAsync, GrabModeAsync, None, cursor[CurMove],
CurrentTime) != GrabSuccess) {
warn("XGrabPointer() failed");
return;
}
/* get initial pointer position */
if (!XQueryPointer(x11.dpy, x11.root, &dummy, &dummy, &x, &y, &i, &i, &ui)) {
warn("XQueryPointer() failed");
warn("XGrabPointer failed");
return;
}
/* handle motions */
do {
XMaskEvent(x11.dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
XMaskEvent(x11.dpy,
MOUSEMASK|ExposureMask|SubstructureRedirectMask,
&ev);
switch (ev.type) {
case ConfigureRequest:
case Expose:
......@@ -674,11 +708,13 @@ movemouse(union arg arg)
handle[ev.type](&ev);
break;
case MotionNotify:
cx = cx+(ev.xmotion.x-x);
cy = cy+(ev.xmotion.y-y);
x = ev.xmotion.x;
y = ev.xmotion.y;
client_move(c, (struct position) { cx, cy });
dx = ev.xmotion.x_root - root_x;
dy = ev.xmotion.y_root - root_y;
root_x = ev.xmotion.x_root;
root_y = ev.xmotion.y_root;
newpos.x = c->dim.x + dx;
newpos.y = c->dim.y + dy;
client_move(c, newpos);
break;
}
} while (ev.type != ButtonRelease);
......@@ -686,10 +722,10 @@ movemouse(union arg arg)
/* check if it has been moved to another monitor */
mon = locaterect(&c->dim.pos, &c->dim.size);
if (mon != seat->selmon) {
debug("Client has changed monitor, transferring");
workspace_detach_client(c->ws, c);
workspace_attach_client(mon->selws, c);
viewmon(mon);
updatefocus();
seat_focus_monitor(seat, mon);
}
XUngrabPointer(x11.dpy, CurrentTime);
......@@ -1880,16 +1916,6 @@ updatewsmbox(struct workspace *ws)
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
viewws(union arg arg)
{
......
......@@ -183,7 +183,7 @@ workspace_set_floating(struct workspace *ws, struct client *c, bool floating)
list_remove(src, c, NULL);
c->floating = floating;
if (ws->selcli == c)
if (dst == ws->floating)
list_prepend(dst, c);
else
list_append(dst, c);
......