]> git.lizzy.rs Git - bspwm.git/commitdiff
Cursor pointer feedbacks for 'grab_pointer'
authorBastien Dejean <nihilhill@gmail.com>
Thu, 10 Jan 2013 16:59:22 +0000 (17:59 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Thu, 10 Jan 2013 16:59:22 +0000 (17:59 +0100)
Makefile
README.md
TODO.md
bspwm.c
bspwm.h
events.c
events.h
window.c
window.h

index 99a28f76cc4574956e5154d99f9e102ff747f70f..5700da1a04bd839b30c22dbb31274381421876a9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 VERSION = 0.4
 
 CC      = gcc
-LIBS    = -lm -lxcb -lxcb-icccm -lxcb-ewmh -lxcb-xinerama
+LIBS    = -lm -lxcb -lxcb-icccm -lxcb-ewmh -lxcb-xinerama -lxcb-cursor
 CFLAGS  = -std=c99 -pedantic -Wall -Wextra -D_POSIX_C_SOURCE=2 -DVERSION=\"$(VERSION)\"
 LDFLAGS = $(LIBS)
 
index a97b9a4719ade632e15d8596d7350f37df75184c..15165beaef87d11425ee9587277433986439bd7c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -310,6 +310,7 @@ Multiple choices:
 - libxcb
 - xcb-util
 - xcb-util-wm
+- xcb-util-cursor
 
 ## Installation
 
diff --git a/TODO.md b/TODO.md
index e57d336cbf6d742d3f5347bdf535f57d42657ad2..5b52db4bea7c24d68d05f5604c7342a08177c6f4 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -1,4 +1,3 @@
-- Window move/resize pointer cursor feedbacks (via *util-cursor*).
 - Grow/shrink through swap.
 - Send to previous/next desktop.
 - Command line completion for *bspc*.
diff --git a/bspwm.c b/bspwm.c
index 21e1d1ee2bafffb6b10447393820bd6165651003..8839b82b750243d9d5723e59f30e1aef1755d572 100644 (file)
--- a/bspwm.c
+++ b/bspwm.c
@@ -12,6 +12,7 @@
 #include <xcb/xcb.h>
 #include <xcb/xcb_event.h>
 #include <xcb/xcb_ewmh.h>
+#include <xcb/xcb_cursor.h>
 #include <xcb/xinerama.h>
 #include "types.h"
 #include "settings.h"
@@ -37,6 +38,7 @@ void cleanup(void)
     while (rule_head != NULL)
         remove_rule(rule_head);
     free(frozen_pointer);
+    xcb_cursor_context_free(cursor_context);
 }
 
 void register_events(void)
@@ -119,6 +121,8 @@ void setup(void)
     frozen_pointer = make_pointer_state();
     last_focused_window = XCB_NONE;
     save_pointer_position(&last_pointer_position);
+    if (xcb_cursor_context_new(&cursor_context, dpy) == -1)
+        warn("Couldn't create the cursor context.\n");
     split_mode = MODE_AUTOMATIC;
     visible = true;
     exit_status = 0;
diff --git a/bspwm.h b/bspwm.h
index 9c8da08fadef5ef619ee2fdcf238cf34a8b66f0d..dcebbeff154a2957b8bb59f5dcc270688d891ce4 100644 (file)
--- a/bspwm.h
+++ b/bspwm.h
@@ -1,6 +1,7 @@
 #ifndef _BSPWM_H
 #define _BSPWM_H
 
+#include "xcb/xcb_cursor.h"
 #include "types.h"
 
 #define ROOT_EVENT_MASK        (XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY)
@@ -33,6 +34,7 @@ rule_t *rule_tail;
 pointer_state_t *frozen_pointer;
 xcb_window_t last_focused_window;
 xcb_point_t last_pointer_position;
+xcb_cursor_context_t *cursor_context;
 
 int exit_status;
 
index b2911aa7193ebcd3111c6179d82baa29268fee30..b71d583a0d0ca2967575b4dc37537b89e0258428 100644 (file)
--- a/events.c
+++ b/events.c
@@ -306,16 +306,24 @@ void grab_pointer(pointer_action_t pac)
                     mid_x = c->floating_rectangle.x + (c->floating_rectangle.width / 2);
                     mid_y = c->floating_rectangle.y + (c->floating_rectangle.height / 2);
                     if (pos.x > mid_x) {
-                        if (pos.y > mid_y)
+                        if (pos.y > mid_y) {
                             frozen_pointer->corner = BOTTOM_RIGHT;
-                        else
+                            window_set_cursor(loc.node->client->window, CURSOR_RESIZE_BR);
+                        } else {
                             frozen_pointer->corner = TOP_RIGHT;
+                            window_set_cursor(loc.node->client->window, CURSOR_RESIZE_TR);
+                        }
                     } else {
-                        if (pos.y > mid_y)
+                        if (pos.y > mid_y) {
                             frozen_pointer->corner = BOTTOM_LEFT;
-                        else
+                            window_set_cursor(loc.node->client->window, CURSOR_RESIZE_BL);
+                        } else {
                             frozen_pointer->corner = TOP_LEFT;
+                            window_set_cursor(loc.node->client->window, CURSOR_RESIZE_TL);
+                        }
                     }
+                } else {
+                    window_set_cursor(loc.node->client->window, CURSOR_MOVE);
                 }
                 break;
         }
@@ -388,6 +396,7 @@ void ungrab_pointer(void)
 {
     PUTS("ungrab pointer");
 
+    window_set_cursor(frozen_pointer->node->client->window, CURSOR_NORMAL);
     update_floating_rectangle(frozen_pointer->node->client);
     monitor_t *m = underlying_monitor(frozen_pointer->node->client);
     if (m != NULL && m != frozen_pointer->monitor) {
index 6f61ad5c2b31591c401a612a487ebad3a848d198..476dc9fcd8ce30f13f3c0a1a029a5247ff5dc24b 100644 (file)
--- a/events.h
+++ b/events.h
@@ -1,6 +1,13 @@
 #ifndef _EVENTS_H
 #define _EVENTS_H
 
+#define CURSOR_NORMAL     "left_ptr"
+#define CURSOR_MOVE       "fleur"
+#define CURSOR_RESIZE_TL  "top_left_corner"
+#define CURSOR_RESIZE_TR  "top_right_corner"
+#define CURSOR_RESIZE_BR  "bottom_right_corner"
+#define CURSOR_RESIZE_BL  "bottom_left_corner"
+
 #include <xcb/xcb.h>
 #include <xcb/xcb_event.h>
 
index a02d42cfa89e427f4df583135b4e884844ac78f7..cf5c7d12a9f09719314c8dded84f8fe27d60a3e1 100644 (file)
--- a/window.c
+++ b/window.c
@@ -5,6 +5,7 @@
 #include <xcb/xcb.h>
 #include <xcb/xcb_event.h>
 #include <xcb/xcb_icccm.h>
+#include <xcb/xcb_cursor.h>
 #include "types.h"
 #include "tree.h"
 #include "bspwm.h"
@@ -498,6 +499,13 @@ void window_show(xcb_window_t win)
     window_set_visibility(win, true);
 }
 
+void window_set_cursor(xcb_window_t win, char *name)
+{
+    xcb_cursor_t cursor = xcb_cursor_load_cursor(cursor_context, name);
+    uint32_t values[] = {cursor};
+    xcb_change_window_attributes(dpy, win, XCB_CW_CURSOR, values);
+}
+
 void toggle_visibility(void)
 {
     visible = !visible;
index 81daf430c2d8109652bd3239de46b5299e8502d1..379acc0d583b8f077cd397275864c16338b79de6 100644 (file)
--- a/window.h
+++ b/window.h
@@ -31,6 +31,7 @@ void window_lower(xcb_window_t);
 void window_set_visibility(xcb_window_t, bool);
 void window_hide(xcb_window_t);
 void window_show(xcb_window_t);
+void window_set_cursor(xcb_window_t, char *);
 void toggle_visibility(void);
 uint32_t get_main_border_color(client_t *, bool, bool);
 void update_floating_rectangle(client_t *);