From: Deiz Date: Sun, 23 Sep 2012 19:43:43 +0000 (-0400) Subject: Display appropriate cursors when resizing or moving floating windows. X-Git-Tag: 4.4~113 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b235c469c16df64092d4476cb82fd26becb32417;p=i3%2Fi3 Display appropriate cursors when resizing or moving floating windows. --- diff --git a/include/floating.h b/include/floating.h index a2f501c5..884d3cf1 100644 --- a/include/floating.h +++ b/include/floating.h @@ -134,8 +134,8 @@ void floating_toggle_hide(xcb_connection_t *conn, Workspace *workspace); * */ void drag_pointer(Con *con, const xcb_button_press_event_t *event, - xcb_window_t confine_to, border_t border, callback_t callback, - const void *extra); + xcb_window_t confine_to, border_t border, int cursor, + callback_t callback, const void *extra); /** * Repositions the CT_FLOATING_CON to have the coordinates specified by diff --git a/include/xcursor.h b/include/xcursor.h index fba82ad3..bfe37c39 100644 --- a/include/xcursor.h +++ b/include/xcursor.h @@ -16,7 +16,12 @@ enum xcursor_cursor_t { XCURSOR_CURSOR_POINTER = 0, XCURSOR_CURSOR_RESIZE_HORIZONTAL, XCURSOR_CURSOR_RESIZE_VERTICAL, + XCURSOR_CURSOR_TOP_LEFT_CORNER, + XCURSOR_CURSOR_TOP_RIGHT_CORNER, + XCURSOR_CURSOR_BOTTOM_LEFT_CORNER, + XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER, XCURSOR_CURSOR_WATCH, + XCURSOR_CURSOR_MOVE, XCURSOR_CURSOR_MAX }; diff --git a/src/floating.c b/src/floating.c index 3d2c1d31..ce81e5fa 100644 --- a/src/floating.c +++ b/src/floating.c @@ -395,7 +395,7 @@ void floating_drag_window(Con *con, const xcb_button_press_event_t *event) { tree_render(); /* Drag the window */ - drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, drag_window_callback, event); + drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, XCURSOR_CURSOR_MOVE, drag_window_callback, event); tree_render(); } @@ -479,13 +479,21 @@ void floating_resize_window(Con *con, const bool proportional, corner |= BORDER_LEFT; else corner |= BORDER_RIGHT; - if (event->event_y <= (con->rect.height / 2)) + int cursor = 0; + if (event->event_y <= (con->rect.height / 2)) { corner |= BORDER_TOP; - else corner |= BORDER_BOTTOM; + cursor = (corner & BORDER_LEFT) ? + XCURSOR_CURSOR_TOP_LEFT_CORNER : XCURSOR_CURSOR_TOP_RIGHT_CORNER; + } + else { + corner |= BORDER_BOTTOM; + cursor = (corner & BORDER_LEFT) ? + XCURSOR_CURSOR_BOTTOM_LEFT_CORNER : XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER; + } struct resize_window_callback_params params = { corner, proportional, event }; - drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, resize_window_callback, ¶ms); + drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, cursor, resize_window_callback, ¶ms); } /* @@ -497,13 +505,16 @@ void floating_resize_window(Con *con, const bool proportional, * */ void drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_window_t - confine_to, border_t border, callback_t callback, const void *extra) + confine_to, border_t border, int cursor, callback_t callback, const void *extra) { uint32_t new_x, new_y; Rect old_rect = { 0, 0, 0, 0 }; if (con != NULL) memcpy(&old_rect, &(con->rect), sizeof(Rect)); + Cursor xcursor = (cursor && xcursor_supported) ? + xcursor_get_cursor(cursor) : XCB_NONE; + /* Grab the pointer */ xcb_grab_pointer_cookie_t cookie; xcb_grab_pointer_reply_t *reply; @@ -514,7 +525,7 @@ void drag_pointer(Con *con, const xcb_button_press_event_t *event, xcb_window_t XCB_GRAB_MODE_ASYNC, /* pointer events should continue as normal */ XCB_GRAB_MODE_ASYNC, /* keyboard mode */ confine_to, /* confine_to = in which window should the cursor stay */ - XCB_NONE, /* don’t display a special cursor */ + xcursor, /* possibly display a special cursor */ XCB_CURRENT_TIME); if ((reply = xcb_grab_pointer_reply(conn, cookie, NULL)) == NULL) { diff --git a/src/resize.c b/src/resize.c index b65344a2..268dc3fb 100644 --- a/src/resize.c +++ b/src/resize.c @@ -106,7 +106,7 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation, const struct callback_params params = { orientation, output, helpwin, &new_position }; - drag_pointer(NULL, event, grabwin, BORDER_TOP, resize_callback, ¶ms); + drag_pointer(NULL, event, grabwin, BORDER_TOP, 0, resize_callback, ¶ms); xcb_destroy_window(conn, helpwin); xcb_destroy_window(conn, grabwin); diff --git a/src/xcursor.c b/src/xcursor.c index 7683b0d3..90fd69dd 100644 --- a/src/xcursor.c +++ b/src/xcursor.c @@ -34,10 +34,15 @@ static Cursor load_cursor(const char *name) { } void xcursor_load_cursors(void) { - cursors[XCURSOR_CURSOR_POINTER] = load_cursor("left_ptr"); - cursors[XCURSOR_CURSOR_RESIZE_HORIZONTAL] = load_cursor("sb_h_double_arrow"); - cursors[XCURSOR_CURSOR_RESIZE_VERTICAL] = load_cursor("sb_v_double_arrow"); - cursors[XCURSOR_CURSOR_WATCH] = load_cursor("watch"); + cursors[XCURSOR_CURSOR_POINTER] = load_cursor("left_ptr"); + cursors[XCURSOR_CURSOR_RESIZE_HORIZONTAL] = load_cursor("sb_h_double_arrow"); + cursors[XCURSOR_CURSOR_RESIZE_VERTICAL] = load_cursor("sb_v_double_arrow"); + cursors[XCURSOR_CURSOR_WATCH] = load_cursor("watch"); + cursors[XCURSOR_CURSOR_MOVE] = load_cursor("fleur"); + cursors[XCURSOR_CURSOR_TOP_LEFT_CORNER] = load_cursor("top_left_corner"); + cursors[XCURSOR_CURSOR_TOP_RIGHT_CORNER] = load_cursor("top_right_corner"); + cursors[XCURSOR_CURSOR_BOTTOM_LEFT_CORNER] = load_cursor("bottom_left_corner"); + cursors[XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER] = load_cursor("bottom_right_corner"); } /*