Skip to content

Commit

Permalink
Removes legacy move/resize code, and let pointer events go to layers.
Browse files Browse the repository at this point in the history
  • Loading branch information
phkaeser committed Jan 12, 2024
1 parent 59ae724 commit 08c4dde
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 334 deletions.
204 changes: 5 additions & 199 deletions src/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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([email protected]): 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([email protected]): 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,
Expand Down Expand Up @@ -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([email protected]): 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(
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
}
}

/* ------------------------------------------------------------------------- */
Expand Down
62 changes: 0 additions & 62 deletions src/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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;
Expand Down Expand Up @@ -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|.
*
Expand Down
5 changes: 0 additions & 5 deletions src/resizebar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 0 additions & 3 deletions src/titlebar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 8 additions & 7 deletions src/toolkit/workspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ bool wlmtk_workspace_motion(
/* ------------------------------------------------------------------------- */
// TODO([email protected]): 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)
{
Expand All @@ -366,22 +366,23 @@ 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) {
event.type = WLMTK_BUTTON_UP;
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;
}

/* ------------------------------------------------------------------------- */
Expand Down
Loading

0 comments on commit 08c4dde

Please sign in to comment.