]> git.lizzy.rs Git - bspwm.git/commitdiff
Extract pointer functions from events.c
authorBastien Dejean <nihilhill@gmail.com>
Wed, 25 Sep 2013 16:00:01 +0000 (18:00 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Wed, 25 Sep 2013 16:00:01 +0000 (18:00 +0200)
Makefile
Sourcedeps
bspc.c
desktop.c
events.c
events.h
messages.c
pointer.c [new file with mode: 0644]
pointer.h [new file with mode: 0644]
settings.c
tree.c

index 9be45477ba06407abbf21d1c564d8c2b710bfb67..e19ba8d4203faf90e1727af785f8b44718b1f51f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ BASHCPL = $(PREFIX)/share/bash-completion/completions
 ZSHCPL = $(PREFIX)/share/zsh/site-functions
 
 WM_SRC = bspwm.c helpers.c settings.c monitor.c desktop.c tree.c history.c \
-        events.c window.c messages.c query.c restore.c rule.c ewmh.c
+        events.c pointer.c window.c messages.c query.c restore.c rule.c ewmh.c
 WM_OBJ = $(WM_SRC:.c=.o)
 CL_SRC = bspc.c helpers.c
 CL_OBJ = $(CL_SRC:.c=.o)
index da5a36042463f26fc715b8e6bef7fcc7f426a032..a3551bb113bfb3a933244ca30cb55d4ed4ee34d3 100644 (file)
@@ -5,8 +5,9 @@ events.o: events.c bspwm.h events.h ewmh.h helpers.h monitor.h query.h settings.
 ewmh.o: ewmh.c bspwm.h ewmh.h helpers.h settings.h tree.h types.h
 helpers.o: helpers.c bspwm.h helpers.h types.h
 history.o: history.c helpers.h query.h types.h
-messages.o: messages.c bspwm.h desktop.h events.h ewmh.h helpers.h messages.h monitor.h query.h restore.h rule.h settings.h tree.h types.h window.h
+messages.o: messages.c bspwm.h desktop.h ewmh.h helpers.h messages.h monitor.h pointer.h query.h restore.h rule.h settings.h tree.h types.h window.h
 monitor.o: monitor.c bspwm.h desktop.h ewmh.h helpers.h monitor.h query.h settings.h tree.h types.h window.h
+pointer.o: pointer.c bspwm.h helpers.h pointer.h query.h settings.h tree.h types.h window.h
 query.o: query.c bspwm.h desktop.h helpers.h history.h messages.h monitor.h query.h tree.h types.h
 restore.o: restore.c bspwm.h desktop.h ewmh.h helpers.h history.h monitor.h query.h restore.h settings.h tree.h types.h
 rule.o: rule.c bspwm.h ewmh.h helpers.h query.h rule.h types.h window.h
diff --git a/bspc.c b/bspc.c
index 2f85bd6b8b0ad2ef8d6ea1d7e551ed3e3fd1c454..95fdb85d5d4223d746f63056573cb64fd93b2ff0 100644 (file)
--- a/bspc.c
+++ b/bspc.c
@@ -1,5 +1,4 @@
 #include <stdlib.h>
-#include <string.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <unistd.h>
index d50a9c6e450664441cc6c36525fe3e797f708c86..e3ce391783e6be37d6ed54a40494e5f35ffb55c6 100644 (file)
--- a/desktop.c
+++ b/desktop.c
@@ -1,5 +1,4 @@
 #include <stdlib.h>
-#include <string.h>
 #include "bspwm.h"
 #include "desktop.h"
 #include "monitor.h"
index 99834bbf45a7330be0d20a4787a43615d6e31b63..46e1b74d1ff861e00d07cef83378e0f4479cb195 100644 (file)
--- a/events.c
+++ b/events.c
@@ -309,294 +309,3 @@ void handle_state(monitor_t *m, desktop_t *d, node_t *n, xcb_atom_t state, unsig
             set_urgency(m, d, n, !n->client->urgent);
     }
 }
-
-void grab_pointer(pointer_action_t pac)
-{
-    PRINTF("grab pointer %u\n", pac);
-
-    xcb_window_t win = XCB_NONE;
-    xcb_point_t pos;
-
-    query_pointer(&win, &pos);
-
-    coordinates_t loc;
-    if (locate_window(win, &loc)) {
-        client_t *c = NULL;
-        frozen_pointer->position = pos;
-        frozen_pointer->action = pac;
-        c = loc.node->client;
-        frozen_pointer->monitor = loc.monitor;
-        frozen_pointer->desktop = loc.desktop;
-        frozen_pointer->node = loc.node;
-        frozen_pointer->client = c;
-        frozen_pointer->window = c->window;
-        frozen_pointer->horizontal_fence = NULL;
-        frozen_pointer->vertical_fence = NULL;
-
-        switch (pac)  {
-            case ACTION_FOCUS:
-                if (loc.node != mon->desk->focus) {
-                    bool backup = pointer_follows_monitor;
-                    pointer_follows_monitor = false;
-                    focus_node(loc.monitor, loc.desktop, loc.node);
-                    pointer_follows_monitor = backup;
-                } else if (focus_follows_pointer && is_floating(loc.node->client)) {
-                    stack(loc.desktop, loc.node);
-                }
-                break;
-            case ACTION_MOVE:
-            case ACTION_RESIZE_SIDE:
-            case ACTION_RESIZE_CORNER:
-                if (is_tiled(c)) {
-                    frozen_pointer->rectangle = c->tiled_rectangle;
-                    frozen_pointer->is_tiled = true;
-                } else if (is_floating(c)) {
-                    frozen_pointer->rectangle = c->floating_rectangle;
-                    frozen_pointer->is_tiled = false;
-                } else {
-                    frozen_pointer->action = ACTION_NONE;
-                    return;
-                }
-                if (pac == ACTION_RESIZE_SIDE) {
-                    float W = frozen_pointer->rectangle.width;
-                    float H = frozen_pointer->rectangle.height;
-                    float ratio = W / H;
-                    float x = pos.x - frozen_pointer->rectangle.x;
-                    float y = pos.y - frozen_pointer->rectangle.y;
-                    float diag_a = ratio * y;
-                    float diag_b = W - diag_a;
-                    if (x < diag_a) {
-                        if (x < diag_b)
-                            frozen_pointer->side = SIDE_LEFT;
-                        else
-                            frozen_pointer->side = SIDE_BOTTOM;
-                    } else {
-                        if (x < diag_b)
-                            frozen_pointer->side = SIDE_TOP;
-                        else
-                            frozen_pointer->side = SIDE_RIGHT;
-                    }
-                } else if (pac == ACTION_RESIZE_CORNER) {
-                    int16_t mid_x = frozen_pointer->rectangle.x + (frozen_pointer->rectangle.width / 2);
-                    int16_t mid_y = frozen_pointer->rectangle.y + (frozen_pointer->rectangle.height / 2);
-                    if (pos.x > mid_x) {
-                        if (pos.y > mid_y)
-                            frozen_pointer->corner = CORNER_BOTTOM_RIGHT;
-                        else
-                            frozen_pointer->corner = CORNER_TOP_RIGHT;
-                    } else {
-                        if (pos.y > mid_y)
-                            frozen_pointer->corner = CORNER_BOTTOM_LEFT;
-                        else
-                            frozen_pointer->corner = CORNER_TOP_LEFT;
-                    }
-                }
-                if (frozen_pointer->is_tiled) {
-                    if (pac == ACTION_RESIZE_SIDE) {
-                        switch (frozen_pointer->side) {
-                            case SIDE_TOP:
-                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_UP);
-                                break;
-                            case SIDE_RIGHT:
-                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_RIGHT);
-                                break;
-                            case SIDE_BOTTOM:
-                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_DOWN);
-                                break;
-                            case SIDE_LEFT:
-                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_LEFT);
-                                break;
-                        }
-                    } else if (pac == ACTION_RESIZE_CORNER) {
-                        switch (frozen_pointer->corner) {
-                            case CORNER_TOP_LEFT:
-                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_UP);
-                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_LEFT);
-                                break;
-                            case CORNER_TOP_RIGHT:
-                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_UP);
-                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_RIGHT);
-                                break;
-                            case CORNER_BOTTOM_RIGHT:
-                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_DOWN);
-                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_RIGHT);
-                                break;
-                            case CORNER_BOTTOM_LEFT:
-                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_DOWN);
-                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_LEFT);
-                                break;
-                        }
-                    }
-                    if (frozen_pointer->horizontal_fence != NULL)
-                        frozen_pointer->horizontal_ratio = frozen_pointer->horizontal_fence->split_ratio;
-                    if (frozen_pointer->vertical_fence != NULL)
-                        frozen_pointer->vertical_ratio = frozen_pointer->vertical_fence->split_ratio;
-                }
-                break;
-            case ACTION_NONE:
-                break;
-        }
-    } else {
-        if (pac == ACTION_FOCUS) {
-            monitor_t *m = monitor_from_point(pos);
-            if (m != NULL && m != mon)
-                focus_node(m, m->desk, m->desk->focus);
-        }
-        frozen_pointer->action = ACTION_NONE;
-    }
-}
-
-void track_pointer(int root_x, int root_y)
-{
-    if (frozen_pointer->action == ACTION_NONE)
-        return;
-
-    int16_t delta_x, delta_y, x = 0, y = 0, w = 1, h = 1;
-    uint16_t width, height;
-
-    pointer_action_t pac = frozen_pointer->action;
-    monitor_t *m = frozen_pointer->monitor;
-    desktop_t *d = frozen_pointer->desktop;
-    node_t *n = frozen_pointer->node;
-    client_t *c = frozen_pointer->client;
-    xcb_window_t win = frozen_pointer->window;
-    xcb_rectangle_t rect = frozen_pointer->rectangle;
-    node_t *vertical_fence = frozen_pointer->vertical_fence;
-    node_t *horizontal_fence = frozen_pointer->horizontal_fence;
-
-    delta_x = root_x - frozen_pointer->position.x;
-    delta_y = root_y - frozen_pointer->position.y;
-
-    switch (pac) {
-        case ACTION_MOVE:
-            if (frozen_pointer->is_tiled) {
-                xcb_window_t pwin = XCB_NONE;
-                query_pointer(&pwin, NULL);
-                if (pwin == win)
-                    return;
-                coordinates_t loc;
-                bool is_managed = (pwin == XCB_NONE ? false : locate_window(pwin, &loc));
-                if (is_managed && is_tiled(loc.node->client) && loc.monitor == m) {
-                    swap_nodes(n, loc.node);
-                    arrange(m, d);
-                } else {
-                    if (is_managed && loc.monitor == m) {
-                        return;
-                    } else if (!is_managed) {
-                        xcb_point_t pt = (xcb_point_t) {root_x, root_y};
-                        monitor_t *pmon = monitor_from_point(pt);
-                        if (pmon == NULL || pmon == m) {
-                            return;
-                        } else {
-                            loc.monitor = pmon;
-                            loc.desktop = pmon->desk;
-                        }
-                    }
-                    transfer_node(m, d, loc.monitor, loc.desktop, n);
-                    frozen_pointer->monitor = loc.monitor;
-                    frozen_pointer->desktop = loc.desktop;
-                }
-            } else {
-                x = rect.x + delta_x;
-                y = rect.y + delta_y;
-                window_move(win, x, y);
-                c->floating_rectangle.x = x;
-                c->floating_rectangle.y = y;
-                xcb_point_t pt = (xcb_point_t) {root_x, root_y};
-                monitor_t *pmon = monitor_from_point(pt);
-                if (pmon == NULL || pmon == m)
-                    return;
-                transfer_node(m, d, pmon, pmon->desk, n);
-                frozen_pointer->monitor = pmon;
-                frozen_pointer->desktop = pmon->desk;
-            }
-            break;
-        case ACTION_RESIZE_SIDE:
-        case ACTION_RESIZE_CORNER:
-            if (frozen_pointer->is_tiled) {
-                if (vertical_fence != NULL) {
-                    double sr = frozen_pointer->vertical_ratio + (double) delta_x / vertical_fence->rectangle.width;
-                    sr = MAX(0, sr);
-                    sr = MIN(1, sr);
-                    vertical_fence->split_ratio = sr;
-                }
-                if (horizontal_fence != NULL) {
-                    double sr = frozen_pointer->horizontal_ratio + (double) delta_y / horizontal_fence->rectangle.height;
-                    sr = MAX(0, sr);
-                    sr = MIN(1, sr);
-                    horizontal_fence->split_ratio = sr;
-                }
-                arrange(mon, mon->desk);
-            } else {
-                if (pac == ACTION_RESIZE_SIDE) {
-                    switch (frozen_pointer->side) {
-                        case SIDE_TOP:
-                            x = rect.x;
-                            y = rect.y + delta_y;
-                            w = rect.width;
-                            h = rect.height - delta_y;
-                            break;
-                        case SIDE_RIGHT:
-                            x = rect.x;
-                            y = rect.y;
-                            w = rect.width + delta_x;
-                            h = rect.height;
-                            break;
-                        case SIDE_BOTTOM:
-                            x = rect.x;
-                            y = rect.y;
-                            w = rect.width;
-                            h = rect.height + delta_y;
-                            break;
-                        case SIDE_LEFT:
-                            x = rect.x + delta_x;
-                            y = rect.y;
-                            w = rect.width - delta_x;
-                            h = rect.height;
-                            break;
-                    }
-                    width = MAX(1, w);
-                    height = MAX(1, h);
-                    window_move_resize(win, x, y, width, height);
-                    c->floating_rectangle = (xcb_rectangle_t) {x, y, width, height};
-                    window_draw_border(n, d->focus == n, mon == m);
-                } else if (pac == ACTION_RESIZE_CORNER) {
-                    switch (frozen_pointer->corner) {
-                        case CORNER_TOP_LEFT:
-                            x = rect.x + delta_x;
-                            y = rect.y + delta_y;
-                            w = rect.width - delta_x;
-                            h = rect.height - delta_y;
-                            break;
-                        case CORNER_TOP_RIGHT:
-                            x = rect.x;
-                            y = rect.y + delta_y;
-                            w = rect.width + delta_x;
-                            h = rect.height - delta_y;
-                            break;
-                        case CORNER_BOTTOM_LEFT:
-                            x = rect.x + delta_x;
-                            y = rect.y;
-                            w = rect.width - delta_x;
-                            h = rect.height + delta_y;
-                            break;
-                        case CORNER_BOTTOM_RIGHT:
-                            x = rect.x;
-                            y = rect.y;
-                            w = rect.width + delta_x;
-                            h = rect.height + delta_y;
-                            break;
-                    }
-                    width = MAX(1, w);
-                    height = MAX(1, h);
-                    window_move_resize(win, x, y, width, height);
-                    c->floating_rectangle = (xcb_rectangle_t) {x, y, width, height};
-                    window_draw_border(n, d->focus == n, mon == m);
-                }
-            }
-            break;
-        case ACTION_FOCUS:
-        case ACTION_NONE:
-            break;
-    }
-}
index eb0bb748066b0a9951bfb43dac26b395f5e1a1b1..973df0d6123d02683fec0ad303b81e0c97db08ed 100644 (file)
--- a/events.h
+++ b/events.h
@@ -19,7 +19,5 @@ void focus_in(xcb_generic_event_t *);
 void enter_notify(xcb_generic_event_t *);
 void motion_notify(xcb_generic_event_t *);
 void handle_state(monitor_t *, desktop_t *, node_t *, xcb_atom_t, unsigned int);
-void grab_pointer(pointer_action_t);
-void track_pointer(int, int);
 
 #endif
index f6747275110a621f3b336d249d0675f0bde29c89..8bda5374e6a7e03fec5788d255138e6e959c1ae1 100644 (file)
@@ -8,10 +8,10 @@
 #include "tree.h"
 #include "desktop.h"
 #include "monitor.h"
+#include "pointer.h"
 #include "window.h"
 #include "rule.h"
 #include "restore.h"
-#include "events.h"
 #include "ewmh.h"
 #include "messages.h"
 
diff --git a/pointer.c b/pointer.c
new file mode 100644 (file)
index 0000000..0accb54
--- /dev/null
+++ b/pointer.c
@@ -0,0 +1,297 @@
+#include "bspwm.h"
+#include "settings.h"
+#include "tree.h"
+#include "window.h"
+#include "query.h"
+#include "pointer.h"
+
+void grab_pointer(pointer_action_t pac)
+{
+    PRINTF("grab pointer %u\n", pac);
+
+    xcb_window_t win = XCB_NONE;
+    xcb_point_t pos;
+
+    query_pointer(&win, &pos);
+
+    coordinates_t loc;
+    if (locate_window(win, &loc)) {
+        client_t *c = NULL;
+        frozen_pointer->position = pos;
+        frozen_pointer->action = pac;
+        c = loc.node->client;
+        frozen_pointer->monitor = loc.monitor;
+        frozen_pointer->desktop = loc.desktop;
+        frozen_pointer->node = loc.node;
+        frozen_pointer->client = c;
+        frozen_pointer->window = c->window;
+        frozen_pointer->horizontal_fence = NULL;
+        frozen_pointer->vertical_fence = NULL;
+
+        switch (pac)  {
+            case ACTION_FOCUS:
+                if (loc.node != mon->desk->focus) {
+                    bool backup = pointer_follows_monitor;
+                    pointer_follows_monitor = false;
+                    focus_node(loc.monitor, loc.desktop, loc.node);
+                    pointer_follows_monitor = backup;
+                } else if (focus_follows_pointer && is_floating(loc.node->client)) {
+                    stack(loc.desktop, loc.node);
+                }
+                break;
+            case ACTION_MOVE:
+            case ACTION_RESIZE_SIDE:
+            case ACTION_RESIZE_CORNER:
+                if (is_tiled(c)) {
+                    frozen_pointer->rectangle = c->tiled_rectangle;
+                    frozen_pointer->is_tiled = true;
+                } else if (is_floating(c)) {
+                    frozen_pointer->rectangle = c->floating_rectangle;
+                    frozen_pointer->is_tiled = false;
+                } else {
+                    frozen_pointer->action = ACTION_NONE;
+                    return;
+                }
+                if (pac == ACTION_RESIZE_SIDE) {
+                    float W = frozen_pointer->rectangle.width;
+                    float H = frozen_pointer->rectangle.height;
+                    float ratio = W / H;
+                    float x = pos.x - frozen_pointer->rectangle.x;
+                    float y = pos.y - frozen_pointer->rectangle.y;
+                    float diag_a = ratio * y;
+                    float diag_b = W - diag_a;
+                    if (x < diag_a) {
+                        if (x < diag_b)
+                            frozen_pointer->side = SIDE_LEFT;
+                        else
+                            frozen_pointer->side = SIDE_BOTTOM;
+                    } else {
+                        if (x < diag_b)
+                            frozen_pointer->side = SIDE_TOP;
+                        else
+                            frozen_pointer->side = SIDE_RIGHT;
+                    }
+                } else if (pac == ACTION_RESIZE_CORNER) {
+                    int16_t mid_x = frozen_pointer->rectangle.x + (frozen_pointer->rectangle.width / 2);
+                    int16_t mid_y = frozen_pointer->rectangle.y + (frozen_pointer->rectangle.height / 2);
+                    if (pos.x > mid_x) {
+                        if (pos.y > mid_y)
+                            frozen_pointer->corner = CORNER_BOTTOM_RIGHT;
+                        else
+                            frozen_pointer->corner = CORNER_TOP_RIGHT;
+                    } else {
+                        if (pos.y > mid_y)
+                            frozen_pointer->corner = CORNER_BOTTOM_LEFT;
+                        else
+                            frozen_pointer->corner = CORNER_TOP_LEFT;
+                    }
+                }
+                if (frozen_pointer->is_tiled) {
+                    if (pac == ACTION_RESIZE_SIDE) {
+                        switch (frozen_pointer->side) {
+                            case SIDE_TOP:
+                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_UP);
+                                break;
+                            case SIDE_RIGHT:
+                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_RIGHT);
+                                break;
+                            case SIDE_BOTTOM:
+                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_DOWN);
+                                break;
+                            case SIDE_LEFT:
+                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_LEFT);
+                                break;
+                        }
+                    } else if (pac == ACTION_RESIZE_CORNER) {
+                        switch (frozen_pointer->corner) {
+                            case CORNER_TOP_LEFT:
+                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_UP);
+                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_LEFT);
+                                break;
+                            case CORNER_TOP_RIGHT:
+                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_UP);
+                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_RIGHT);
+                                break;
+                            case CORNER_BOTTOM_RIGHT:
+                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_DOWN);
+                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_RIGHT);
+                                break;
+                            case CORNER_BOTTOM_LEFT:
+                                frozen_pointer->horizontal_fence = find_fence(loc.node, DIR_DOWN);
+                                frozen_pointer->vertical_fence = find_fence(loc.node, DIR_LEFT);
+                                break;
+                        }
+                    }
+                    if (frozen_pointer->horizontal_fence != NULL)
+                        frozen_pointer->horizontal_ratio = frozen_pointer->horizontal_fence->split_ratio;
+                    if (frozen_pointer->vertical_fence != NULL)
+                        frozen_pointer->vertical_ratio = frozen_pointer->vertical_fence->split_ratio;
+                }
+                break;
+            case ACTION_NONE:
+                break;
+        }
+    } else {
+        if (pac == ACTION_FOCUS) {
+            monitor_t *m = monitor_from_point(pos);
+            if (m != NULL && m != mon)
+                focus_node(m, m->desk, m->desk->focus);
+        }
+        frozen_pointer->action = ACTION_NONE;
+    }
+}
+
+void track_pointer(int root_x, int root_y)
+{
+    if (frozen_pointer->action == ACTION_NONE)
+        return;
+
+    int16_t delta_x, delta_y, x = 0, y = 0, w = 1, h = 1;
+    uint16_t width, height;
+
+    pointer_action_t pac = frozen_pointer->action;
+    monitor_t *m = frozen_pointer->monitor;
+    desktop_t *d = frozen_pointer->desktop;
+    node_t *n = frozen_pointer->node;
+    client_t *c = frozen_pointer->client;
+    xcb_window_t win = frozen_pointer->window;
+    xcb_rectangle_t rect = frozen_pointer->rectangle;
+    node_t *vertical_fence = frozen_pointer->vertical_fence;
+    node_t *horizontal_fence = frozen_pointer->horizontal_fence;
+
+    delta_x = root_x - frozen_pointer->position.x;
+    delta_y = root_y - frozen_pointer->position.y;
+
+    switch (pac) {
+        case ACTION_MOVE:
+            if (frozen_pointer->is_tiled) {
+                xcb_window_t pwin = XCB_NONE;
+                query_pointer(&pwin, NULL);
+                if (pwin == win)
+                    return;
+                coordinates_t loc;
+                bool is_managed = (pwin == XCB_NONE ? false : locate_window(pwin, &loc));
+                if (is_managed && is_tiled(loc.node->client) && loc.monitor == m) {
+                    swap_nodes(n, loc.node);
+                    arrange(m, d);
+                } else {
+                    if (is_managed && loc.monitor == m) {
+                        return;
+                    } else if (!is_managed) {
+                        xcb_point_t pt = (xcb_point_t) {root_x, root_y};
+                        monitor_t *pmon = monitor_from_point(pt);
+                        if (pmon == NULL || pmon == m) {
+                            return;
+                        } else {
+                            loc.monitor = pmon;
+                            loc.desktop = pmon->desk;
+                        }
+                    }
+                    transfer_node(m, d, loc.monitor, loc.desktop, n);
+                    frozen_pointer->monitor = loc.monitor;
+                    frozen_pointer->desktop = loc.desktop;
+                }
+            } else {
+                x = rect.x + delta_x;
+                y = rect.y + delta_y;
+                window_move(win, x, y);
+                c->floating_rectangle.x = x;
+                c->floating_rectangle.y = y;
+                xcb_point_t pt = (xcb_point_t) {root_x, root_y};
+                monitor_t *pmon = monitor_from_point(pt);
+                if (pmon == NULL || pmon == m)
+                    return;
+                transfer_node(m, d, pmon, pmon->desk, n);
+                frozen_pointer->monitor = pmon;
+                frozen_pointer->desktop = pmon->desk;
+            }
+            break;
+        case ACTION_RESIZE_SIDE:
+        case ACTION_RESIZE_CORNER:
+            if (frozen_pointer->is_tiled) {
+                if (vertical_fence != NULL) {
+                    double sr = frozen_pointer->vertical_ratio + (double) delta_x / vertical_fence->rectangle.width;
+                    sr = MAX(0, sr);
+                    sr = MIN(1, sr);
+                    vertical_fence->split_ratio = sr;
+                }
+                if (horizontal_fence != NULL) {
+                    double sr = frozen_pointer->horizontal_ratio + (double) delta_y / horizontal_fence->rectangle.height;
+                    sr = MAX(0, sr);
+                    sr = MIN(1, sr);
+                    horizontal_fence->split_ratio = sr;
+                }
+                arrange(mon, mon->desk);
+            } else {
+                if (pac == ACTION_RESIZE_SIDE) {
+                    switch (frozen_pointer->side) {
+                        case SIDE_TOP:
+                            x = rect.x;
+                            y = rect.y + delta_y;
+                            w = rect.width;
+                            h = rect.height - delta_y;
+                            break;
+                        case SIDE_RIGHT:
+                            x = rect.x;
+                            y = rect.y;
+                            w = rect.width + delta_x;
+                            h = rect.height;
+                            break;
+                        case SIDE_BOTTOM:
+                            x = rect.x;
+                            y = rect.y;
+                            w = rect.width;
+                            h = rect.height + delta_y;
+                            break;
+                        case SIDE_LEFT:
+                            x = rect.x + delta_x;
+                            y = rect.y;
+                            w = rect.width - delta_x;
+                            h = rect.height;
+                            break;
+                    }
+                    width = MAX(1, w);
+                    height = MAX(1, h);
+                    window_move_resize(win, x, y, width, height);
+                    c->floating_rectangle = (xcb_rectangle_t) {x, y, width, height};
+                    window_draw_border(n, d->focus == n, mon == m);
+                } else if (pac == ACTION_RESIZE_CORNER) {
+                    switch (frozen_pointer->corner) {
+                        case CORNER_TOP_LEFT:
+                            x = rect.x + delta_x;
+                            y = rect.y + delta_y;
+                            w = rect.width - delta_x;
+                            h = rect.height - delta_y;
+                            break;
+                        case CORNER_TOP_RIGHT:
+                            x = rect.x;
+                            y = rect.y + delta_y;
+                            w = rect.width + delta_x;
+                            h = rect.height - delta_y;
+                            break;
+                        case CORNER_BOTTOM_LEFT:
+                            x = rect.x + delta_x;
+                            y = rect.y;
+                            w = rect.width - delta_x;
+                            h = rect.height + delta_y;
+                            break;
+                        case CORNER_BOTTOM_RIGHT:
+                            x = rect.x;
+                            y = rect.y;
+                            w = rect.width + delta_x;
+                            h = rect.height + delta_y;
+                            break;
+                    }
+                    width = MAX(1, w);
+                    height = MAX(1, h);
+                    window_move_resize(win, x, y, width, height);
+                    c->floating_rectangle = (xcb_rectangle_t) {x, y, width, height};
+                    window_draw_border(n, d->focus == n, mon == m);
+                }
+            }
+            break;
+        case ACTION_FOCUS:
+        case ACTION_NONE:
+            break;
+    }
+}
diff --git a/pointer.h b/pointer.h
new file mode 100644 (file)
index 0000000..cdd4ef2
--- /dev/null
+++ b/pointer.h
@@ -0,0 +1,7 @@
+#ifndef _POINTER_H
+#define _POINTER_H
+
+void grab_pointer(pointer_action_t);
+void track_pointer(int, int);
+
+#endif
index f9e63d8f7382e4d752084d589e8404741857adc1..b6eeac98f1e10fc425bbc0b240dcf44026c7bb0b 100644 (file)
@@ -1,5 +1,4 @@
 #include <stdlib.h>
-#include <string.h>
 #include <unistd.h>
 #include <sys/wait.h>
 #include "bspwm.h"
diff --git a/tree.c b/tree.c
index 79dc1355b8f5d25e5c150b733c8e81b3fbc5403d..fcb8250b54901fe22c4be755bcd79d894b43339d 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -1,4 +1,3 @@
-#include <string.h>
 #include <math.h>
 #include <limits.h>
 #include <float.h>