diff --git a/src/cursor.c b/src/cursor.c index ae50e0e3..e1905270 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -107,7 +107,6 @@ wlmaker_cursor_t *wlmaker_cursor_create(wlmaker_server_t *server_ptr) // // https://drewdevault.com/2018/07/17/Input-handling-in-wlroots.html - // TODO: Need a mode for 'normal', 'move', 'resize'. wlmtk_util_connect_listener_signal( &cursor_ptr->wlr_cursor_ptr->events.motion, &cursor_ptr->motion_listener, @@ -164,71 +163,6 @@ void wlmaker_cursor_attach_input_device( wlr_input_device_ptr); } -/* ------------------------------------------------------------------------- */ -void wlmaker_cursor_begin_move( - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr) -{ - if (view_ptr != wlmaker_workspace_get_activated_view( - wlmaker_server_get_current_workspace(cursor_ptr->server_ptr))) { - bs_log(BS_WARNING, "Denying move request from non-activated view."); - return; - } - - cursor_ptr->grabbed_view_ptr = view_ptr; - int x, y; - wlmaker_view_get_position(cursor_ptr->grabbed_view_ptr, &x, &y); - // TODO(kaeser@gubbe.ch): Inconsistent to have separate meaning of grab_x - // and grab_y for MOVE vs RESIZE. Should be cleaned up. - cursor_ptr->grab_x = cursor_ptr->wlr_cursor_ptr->x - x; - cursor_ptr->grab_y = cursor_ptr->wlr_cursor_ptr->y - y; - cursor_ptr->mode = WLMAKER_CURSOR_MOVE; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_cursor_begin_resize( - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr, - uint32_t edges) -{ - if (view_ptr != wlmaker_workspace_get_activated_view( - wlmaker_server_get_current_workspace(cursor_ptr->server_ptr))) { - bs_log(BS_WARNING, "Denying resize request from non-activated view."); - return; - } - - cursor_ptr->grabbed_view_ptr = view_ptr; - cursor_ptr->grab_x = cursor_ptr->wlr_cursor_ptr->x; - cursor_ptr->grab_y = cursor_ptr->wlr_cursor_ptr->y; - cursor_ptr->mode = WLMAKER_CURSOR_RESIZE; - - uint32_t width, height; - wlmaker_view_get_size(view_ptr, &width, &height); - cursor_ptr->grabbed_geobox.width = width; - cursor_ptr->grabbed_geobox.height = height; - wlmaker_view_get_position(view_ptr, - &cursor_ptr->grabbed_geobox.x, - &cursor_ptr->grabbed_geobox.y); - cursor_ptr->resize_edges = edges; -} - -/* ------------------------------------------------------------------------- */ -void wlmaker_cursor_unmap_view( - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr) -{ - if (cursor_ptr->grabbed_view_ptr == view_ptr) { - cursor_ptr->grabbed_view_ptr = NULL; - cursor_ptr->mode = WLMAKER_CURSOR_PASSTHROUGH; - } - - if (cursor_ptr->under_cursor_view_ptr == view_ptr) { - // TODO(kaeser@gubbe.ch): Should eavluate which of the view is now - // below the cursor and update "pointer focus" accordingly. - update_under_cursor_view(cursor_ptr, NULL); - } -} - /* ------------------------------------------------------------------------- */ void wlmaker_cursor_get_position( const wlmaker_cursor_t *cursor_ptr, @@ -306,44 +240,14 @@ void handle_button(struct wl_listener *listener_ptr, listener_ptr, cursor_ptr, button_listener); struct wlr_pointer_button_event *wlr_pointer_button_event_ptr = data_ptr; - wlmtk_workspace_button( + bool consumed = wlmtk_workspace_button( wlmaker_workspace_wlmtk(wlmaker_server_get_current_workspace( cursor_ptr->server_ptr)), wlr_pointer_button_event_ptr); - if (true) return; // FIXME - - struct wlr_keyboard *wlr_keyboard_ptr = wlr_seat_get_keyboard( - cursor_ptr->server_ptr->wlr_seat_ptr); - if (NULL != wlr_keyboard_ptr) { - uint32_t modifiers = wlr_keyboard_get_modifiers(wlr_keyboard_ptr); - if (wlmaker_config_window_drag_modifiers != 0 && - wlmaker_config_window_drag_modifiers == modifiers && - wlr_pointer_button_event_ptr->state == WLR_BUTTON_PRESSED) { - struct wlr_surface *wlr_surface_ptr; - double rel_x, rel_y; - wlmaker_view_t *view_ptr = wlmaker_view_at( - cursor_ptr->server_ptr, - cursor_ptr->wlr_cursor_ptr->x, - cursor_ptr->wlr_cursor_ptr->y, - &wlr_surface_ptr, - &rel_x, - &rel_y); - if (NULL != view_ptr) { - wlmaker_workspace_raise_view( - wlmaker_server_get_current_workspace( - cursor_ptr->server_ptr), - view_ptr); - wlmaker_workspace_activate_view( - wlmaker_server_get_current_workspace( - cursor_ptr->server_ptr), - view_ptr); - update_under_cursor_view(cursor_ptr, view_ptr); - wlmaker_cursor_begin_move(cursor_ptr, view_ptr); - return; - } - } - } + // TODO(kaeser@gubbe.ch): The code below is for the pre-toolkit version. + // Remove it, once we're fully on toolkit. + if (consumed) return; // Notify the client with pointer focus that a button press has occurred. wlr_seat_pointer_notify_button( @@ -373,7 +277,6 @@ void handle_button(struct wl_listener *listener_ptr, if (wlr_pointer_button_event_ptr->state == WLR_BUTTON_RELEASED) { wl_signal_emit(&cursor_ptr->button_release_event, data_ptr); - cursor_ptr->mode = WLMAKER_CURSOR_PASSTHROUGH; } } @@ -481,109 +384,12 @@ void handle_seat_request_set_cursor( */ void process_motion(wlmaker_cursor_t *cursor_ptr, uint32_t time_msec) { - bool rv = wlmtk_workspace_motion( + wlmtk_workspace_motion( wlmaker_workspace_wlmtk(wlmaker_server_get_current_workspace( cursor_ptr->server_ptr)), cursor_ptr->wlr_cursor_ptr->x, cursor_ptr->wlr_cursor_ptr->y, time_msec); - - if (!rv) { // FIXME - wlr_cursor_set_xcursor( - cursor_ptr->wlr_cursor_ptr, - cursor_ptr->wlr_xcursor_manager_ptr, - "left_ptr"); - } - - if (true) return; - - if (cursor_ptr->mode == WLMAKER_CURSOR_MOVE) { - wlmaker_view_set_position( - cursor_ptr->grabbed_view_ptr, - cursor_ptr->wlr_cursor_ptr->x - cursor_ptr->grab_x, - cursor_ptr->wlr_cursor_ptr->y - cursor_ptr->grab_y); - return; - } else if (cursor_ptr->mode == WLMAKER_CURSOR_RESIZE) { - - // The geometry describes the overall shell geometry *relative* to the - // node position. This may eg. include client-side decoration, that - // may be placed in an extra surface above the nominal window (and - // node). - // - // Thus the position and dimensions of the visible area is given by - // the geobox position (relative to the node position) and with x height. - - double x = cursor_ptr->wlr_cursor_ptr->x - cursor_ptr->grab_x; - double y = cursor_ptr->wlr_cursor_ptr->y - cursor_ptr->grab_y; - - // Update new boundaries by the relative movement. - int top = cursor_ptr->grabbed_geobox.y; - int bottom = cursor_ptr->grabbed_geobox.y + cursor_ptr->grabbed_geobox.height; - if (cursor_ptr->resize_edges & WLR_EDGE_TOP) { - top += y; - if (top >= bottom) top = bottom - 1; - } else if (cursor_ptr->resize_edges & WLR_EDGE_BOTTOM) { - bottom += y; - if (bottom <= top) bottom = top + 1; - } - - int left = cursor_ptr->grabbed_geobox.x; - int right = cursor_ptr->grabbed_geobox.x + cursor_ptr->grabbed_geobox.width; - if (cursor_ptr->resize_edges & WLR_EDGE_LEFT) { - left += x; - if (left >= right) left = right - 1 ; - } else if (cursor_ptr->resize_edges & WLR_EDGE_RIGHT) { - right += x; - if (right <= left) right = left + 1; - } - - wlmaker_view_set_position(cursor_ptr->grabbed_view_ptr, left, top); - wlmaker_view_set_size(cursor_ptr->grabbed_view_ptr, - right - left, bottom - top); - return; - } - - double rel_x, rel_y; - struct wlr_surface *wlr_surface_ptr = NULL; - wlmaker_view_t *view_ptr = wlmaker_view_at( - cursor_ptr->server_ptr, - cursor_ptr->wlr_cursor_ptr->x, - cursor_ptr->wlr_cursor_ptr->y, - &wlr_surface_ptr, - &rel_x, - &rel_y); - update_under_cursor_view(cursor_ptr, view_ptr); - if (NULL == view_ptr) { - wlr_cursor_set_xcursor( - cursor_ptr->wlr_cursor_ptr, - cursor_ptr->wlr_xcursor_manager_ptr, - "left_ptr"); - } else { - wlmaker_view_handle_motion( - view_ptr, - cursor_ptr->wlr_cursor_ptr->x, - cursor_ptr->wlr_cursor_ptr->y); - } - - if (NULL == wlr_surface_ptr) { - // Clear pointer focus, so that future button events are no longer sent - // to the surface that had the focus. - wlr_seat_pointer_clear_focus(cursor_ptr->server_ptr->wlr_seat_ptr); - - } else { - // The notify_enter() function gives the pointer focus to the specified - // surface. The seat will send future button events there. - wlr_seat_pointer_notify_enter( - cursor_ptr->server_ptr->wlr_seat_ptr, - wlr_surface_ptr, - rel_x, - rel_y); - wlr_seat_pointer_notify_motion( - cursor_ptr->server_ptr->wlr_seat_ptr, - time_msec, - rel_x, - rel_y); - } } /* ------------------------------------------------------------------------- */ diff --git a/src/cursor.h b/src/cursor.h index 7ca85439..3d658e08 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -30,16 +30,6 @@ typedef struct _wlmaker_cursor_t wlmaker_cursor_t; extern "C" { #endif // __cplusplus -/** Mode of the cursor. */ -typedef enum { - /** Cursor movements are passed on to the client. */ - WLMAKER_CURSOR_PASSTHROUGH, - /** View-move mode. Movements kept and used to propel the view. */ - WLMAKER_CURSOR_MOVE, - /** Resize mode. Movements kept and used to resize the view. */ - WLMAKER_CURSOR_RESIZE, -} wlmaker_cursor_mode_t; - /** State and tools for handling wlmaker cursors. */ struct _wlmaker_cursor_t { /** Back-link to wlmaker_server_t. */ @@ -64,27 +54,8 @@ struct _wlmaker_cursor_t { /** Listener for the `request_set_cursor` event of `wlr_seat`. */ struct wl_listener seat_request_set_cursor_listener; - /** Mode that the cursor is in, eg. moving or resizing. */ - wlmaker_cursor_mode_t mode; - /** The currently grabbed view, when in "move" mode. */ - wlmaker_view_t *grabbed_view_ptr; /** The view that is currently active and under the cursor. */ wlmaker_view_t *under_cursor_view_ptr; - /** - * Horizontal position of when the move was activated, relative to the - * grabbed view. - */ - double grab_x; - /** - * Vertical position of when the move was activated, relative to the - * grabbed view. - */ - double grab_y; - /** Geometry at the time the move was initiated. */ - struct wlr_box grabbed_geobox; - /** Edges to resize along. */ - uint32_t resize_edges; - /** wlmaker internal: catch 'release' events of cursors. */ struct wl_signal button_release_event; @@ -116,39 +87,6 @@ void wlmaker_cursor_attach_input_device( wlmaker_cursor_t *cursor_ptr, struct wlr_input_device *wlr_input_device_ptr); -/** - * Begins a "move" interaction for the given view. - * - * @param cursor_ptr - * @param view_ptr - */ -void wlmaker_cursor_begin_move( - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr); - -/** - * Begins a "resize" interaction for the given view. - * - * @param cursor_ptr - * @param view_ptr - * @param edges - */ -void wlmaker_cursor_begin_resize( - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr, - uint32_t edges); - -/** - * Reports |view_ptr| as unmapped. Removes it from the set of views that can - * be called back, etc. - * - * @param cursor_ptr - * @param view_ptr - */ -void wlmaker_cursor_unmap_view( - wlmaker_cursor_t *cursor_ptr, - wlmaker_view_t *view_ptr); - /** * Retrieves the current pointer's position into |*x_ptr|, |*y_ptr|. * diff --git a/src/resizebar.c b/src/resizebar.c index 1fc71a06..5bbb414c 100644 --- a/src/resizebar.c +++ b/src/resizebar.c @@ -228,11 +228,6 @@ void _resizebar_button( case WLR_BUTTON_PRESSED: if (wlmaker_interactive_contains(&resizebar_ptr->interactive, x, y)) { resizebar_ptr->pressed = true; - - wlmaker_cursor_begin_resize( - resizebar_ptr->interactive.cursor_ptr, - resizebar_ptr->view_ptr, - resizebar_ptr->edges); } break; diff --git a/src/titlebar.c b/src/titlebar.c index b1f55a0c..99395349 100644 --- a/src/titlebar.c +++ b/src/titlebar.c @@ -223,9 +223,6 @@ void _titlebar_motion( (fabs(titlebar_ptr->clicked_x - x) > minimal_move || fabs(titlebar_ptr->clicked_y - y) > minimal_move)) { titlebar_ptr->state = TITLEBAR_MOVING; - wlmaker_cursor_begin_move( - titlebar_ptr->interactive.cursor_ptr, - titlebar_ptr->view_ptr); wlr_cursor_set_xcursor( interactive_ptr->cursor_ptr->wlr_cursor_ptr, diff --git a/src/toolkit/workspace.c b/src/toolkit/workspace.c index e8c30b8b..0314a634 100644 --- a/src/toolkit/workspace.c +++ b/src/toolkit/workspace.c @@ -355,7 +355,7 @@ bool wlmtk_workspace_motion( /* ------------------------------------------------------------------------- */ // TODO(kaeser@gubbe.ch): Improve this, has multiple bugs: It won't keep // different buttons apart, and there's currently no test associated. -void wlmtk_workspace_button( +bool wlmtk_workspace_button( wlmtk_workspace_t *workspace_ptr, const struct wlr_pointer_button_event *event_ptr) { @@ -366,7 +366,7 @@ void wlmtk_workspace_button( event.time_msec = event_ptr->time_msec; if (WLR_BUTTON_PRESSED == event_ptr->state) { event.type = WLMTK_BUTTON_DOWN; - wlmtk_element_pointer_button( + return wlmtk_element_pointer_button( &workspace_ptr->super_container.super_element, &event); } else if (WLR_BUTTON_RELEASED == event_ptr->state) { @@ -374,14 +374,15 @@ void wlmtk_workspace_button( wlmtk_element_pointer_button( &workspace_ptr->super_container.super_element, &event); event.type = WLMTK_BUTTON_CLICK; - wlmtk_element_pointer_button( + return wlmtk_element_pointer_button( &workspace_ptr->super_container.super_element, &event); - } else { - bs_log(BS_WARNING, - "Workspace %p: Unhandled state 0x%x for button 0x%x", - workspace_ptr, event_ptr->state, event_ptr->button); } + + bs_log(BS_WARNING, + "Workspace %p: Unhandled state 0x%x for button 0x%x", + workspace_ptr, event_ptr->state, event_ptr->button); + return false; } /* ------------------------------------------------------------------------- */ diff --git a/src/toolkit/workspace.h b/src/toolkit/workspace.h index 5d04e724..6676c477 100644 --- a/src/toolkit/workspace.h +++ b/src/toolkit/workspace.h @@ -152,8 +152,10 @@ bool wlmtk_workspace_motion( * * @param workspace_ptr * @param event_ptr + * + * @return Whether the button was consumed. */ -void wlmtk_workspace_button( +bool wlmtk_workspace_button( wlmtk_workspace_t *workspace_ptr, const struct wlr_pointer_button_event *event_ptr); diff --git a/src/view.c b/src/view.c index 9507d9cf..dc7ec88b 100644 --- a/src/view.c +++ b/src/view.c @@ -705,8 +705,6 @@ void wlmaker_view_unmap(wlmaker_view_t *view_ptr) view_ptr->workspace_ptr = NULL; wlmaker_view_apply_decoration(view_ptr); - wlmaker_cursor_unmap_view(view_ptr->server_ptr->cursor_ptr, view_ptr); - wl_signal_emit(&view_ptr->server_ptr->view_unmapped_event, view_ptr); } diff --git a/src/xdg_toplevel.c b/src/xdg_toplevel.c index 107738fc..36acd050 100644 --- a/src/xdg_toplevel.c +++ b/src/xdg_toplevel.c @@ -110,12 +110,6 @@ static void handle_toplevel_fullscreen( static void handle_toplevel_minimize( struct wl_listener *listener_ptr, void *data_ptr); -static void handle_toplevel_move( - struct wl_listener *listener_ptr, - void *data_ptr); -static void handle_toplevel_resize( - struct wl_listener *listener_ptr, - void *data_ptr); static void handle_toplevel_show_window_menu( struct wl_listener *listener_ptr, void *data_ptr); @@ -206,14 +200,6 @@ wlmaker_xdg_toplevel_t *wlmaker_xdg_toplevel_create( &wlr_xdg_surface_ptr->toplevel->events.request_minimize, &xdg_toplevel_ptr->toplevel_request_minimize_listener, handle_toplevel_minimize); - wlmtk_util_connect_listener_signal( - &wlr_xdg_surface_ptr->toplevel->events.request_move, - &xdg_toplevel_ptr->toplevel_request_move_listener, - handle_toplevel_move); - wlmtk_util_connect_listener_signal( - &wlr_xdg_surface_ptr->toplevel->events.request_resize, - &xdg_toplevel_ptr->toplevel_request_resize_listener, - handle_toplevel_resize); wlmtk_util_connect_listener_signal( &wlr_xdg_surface_ptr->toplevel->events.request_show_window_menu, &xdg_toplevel_ptr->toplevel_request_show_window_menu_listener, @@ -575,47 +561,6 @@ void handle_toplevel_minimize( wlmaker_view_set_iconified(&xdg_toplevel_ptr->view, true); } -/* ------------------------------------------------------------------------- */ -/** - * Handler for the `move` signal of the `struct wlr_xdg_toplevel`. - * - * @param listener_ptr - * @param data_ptr - */ -void handle_toplevel_move( - struct wl_listener *listener_ptr, - __UNUSED__ void *data_ptr) -{ - wlmaker_xdg_toplevel_t *xdg_toplevel_ptr = wl_container_of( - listener_ptr, xdg_toplevel_ptr, toplevel_request_move_listener); - - wlmaker_cursor_begin_move( - xdg_toplevel_ptr->view.server_ptr->cursor_ptr, - &xdg_toplevel_ptr->view); -} - -/* ------------------------------------------------------------------------- */ -/** - * Handler for the `resize` signal of the `struct wlr_xdg_toplevel`. - * - * @param listener_ptr - * @param data_ptr - */ -void handle_toplevel_resize( - struct wl_listener *listener_ptr, - void *data_ptr) -{ - wlmaker_xdg_toplevel_t *xdg_toplevel_ptr = wl_container_of( - listener_ptr, xdg_toplevel_ptr, toplevel_request_resize_listener); - struct wlr_xdg_toplevel_resize_event *wlr_xdg_toplevel_resize_event_ptr = - data_ptr; - - wlmaker_cursor_begin_resize( - xdg_toplevel_ptr->view.server_ptr->cursor_ptr, - &xdg_toplevel_ptr->view, - wlr_xdg_toplevel_resize_event_ptr->edges); -} - /* ------------------------------------------------------------------------- */ /** * Handler for the `show_window_menu` signal of the `struct wlr_xdg_toplevel`.