frames: Make 1st button/motion handlers take generic events

This will ease handling of touch events through these same handlers.

https://bugzilla.gnome.org/show_bug.cgi?id=770185
This commit is contained in:
Carlos Garnacho 2018-04-15 15:45:02 +02:00
parent e34c330f66
commit 3561082aba

View File

@ -743,16 +743,21 @@ redraw_control (MetaUIFrame *frame,
static gboolean static gboolean
meta_frame_titlebar_event (MetaUIFrame *frame, meta_frame_titlebar_event (MetaUIFrame *frame,
ClutterButtonEvent *event, const ClutterEvent *event,
int action) int action)
{ {
MetaFrameFlags flags; MetaFrameFlags flags;
Display *display; Display *display;
guint32 evtime;
gfloat x, y;
display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
flags = meta_frame_get_flags (frame->meta_window->frame); flags = meta_frame_get_flags (frame->meta_window->frame);
evtime = clutter_event_get_time (event);
clutter_event_get_coords (event, &x, &y);
switch (action) switch (action)
{ {
case G_DESKTOP_TITLEBAR_ACTION_TOGGLE_SHADE: case G_DESKTOP_TITLEBAR_ACTION_TOGGLE_SHADE:
@ -760,9 +765,9 @@ meta_frame_titlebar_event (MetaUIFrame *frame,
if (flags & META_FRAME_ALLOWS_SHADE) if (flags & META_FRAME_ALLOWS_SHADE)
{ {
if (flags & META_FRAME_SHADED) if (flags & META_FRAME_SHADED)
meta_window_unshade (frame->meta_window, event->time); meta_window_unshade (frame->meta_window, evtime);
else else
meta_window_shade (frame->meta_window, event->time); meta_window_shade (frame->meta_window, evtime);
} }
} }
break; break;
@ -808,16 +813,14 @@ meta_frame_titlebar_event (MetaUIFrame *frame,
case G_DESKTOP_TITLEBAR_ACTION_LOWER: case G_DESKTOP_TITLEBAR_ACTION_LOWER:
meta_core_user_lower_and_unfocus (display, meta_core_user_lower_and_unfocus (display,
frame->xwindow, frame->xwindow,
event->time); evtime);
break; break;
case G_DESKTOP_TITLEBAR_ACTION_MENU: case G_DESKTOP_TITLEBAR_ACTION_MENU:
meta_core_show_window_menu (display, meta_core_show_window_menu (display,
frame->xwindow, frame->xwindow,
META_WINDOW_MENU_WM, META_WINDOW_MENU_WM,
event->x, x, y, evtime);
event->y,
event->time);
break; break;
} }
@ -826,7 +829,7 @@ meta_frame_titlebar_event (MetaUIFrame *frame,
static gboolean static gboolean
meta_frame_double_click_event (MetaUIFrame *frame, meta_frame_double_click_event (MetaUIFrame *frame,
ClutterButtonEvent *event) const ClutterEvent *event)
{ {
int action = meta_prefs_get_action_double_click_titlebar (); int action = meta_prefs_get_action_double_click_titlebar ();
@ -839,7 +842,8 @@ meta_frame_middle_click_event (MetaUIFrame *frame,
{ {
int action = meta_prefs_get_action_middle_click_titlebar(); int action = meta_prefs_get_action_middle_click_titlebar();
return meta_frame_titlebar_event (frame, event, action); return meta_frame_titlebar_event (frame, (const ClutterEvent *) event,
action);
} }
static gboolean static gboolean
@ -848,7 +852,8 @@ meta_frame_right_click_event (MetaUIFrame *frame,
{ {
int action = meta_prefs_get_action_right_click_titlebar(); int action = meta_prefs_get_action_right_click_titlebar();
return meta_frame_titlebar_event (frame, event, action); return meta_frame_titlebar_event (frame, (const ClutterEvent *) event,
action);
} }
static gboolean static gboolean
@ -937,10 +942,17 @@ grab_op_from_resize_control (MetaFrameControl control)
static gboolean static gboolean
meta_frame_left_click_event (MetaUIFrame *frame, meta_frame_left_click_event (MetaUIFrame *frame,
ClutterButtonEvent *event) const ClutterEvent *event)
{ {
Display *display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); Display *display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
MetaFrameControl control = get_control (frame, event->x, event->y); MetaFrameControl control;
guint32 evtime, button;
gfloat x, y;
evtime = clutter_event_get_time (event);
clutter_event_get_coords (event, &x, &y);
button = clutter_event_get_button (event);
control = get_control (frame, x, y);
switch (control) switch (control)
{ {
@ -950,7 +962,7 @@ meta_frame_left_click_event (MetaUIFrame *frame,
case META_FRAME_CONTROL_DELETE: case META_FRAME_CONTROL_DELETE:
case META_FRAME_CONTROL_MENU: case META_FRAME_CONTROL_MENU:
case META_FRAME_CONTROL_APPMENU: case META_FRAME_CONTROL_APPMENU:
frame->grab_button = event->button; frame->grab_button = button;
frame->button_state = META_BUTTON_STATE_PRESSED; frame->button_state = META_BUTTON_STATE_PRESSED;
frame->prelit_control = control; frame->prelit_control = control;
redraw_control (frame, control); redraw_control (frame, control);
@ -987,13 +999,12 @@ meta_frame_left_click_event (MetaUIFrame *frame,
frame->xwindow, frame->xwindow,
menu, menu,
&root_rect, &root_rect,
event->time); evtime);
} }
else else
{ {
meta_frames_try_grab_op (frame, META_GRAB_OP_FRAME_BUTTON, meta_frames_try_grab_op (frame, META_GRAB_OP_FRAME_BUTTON,
event->x, event->y, x, y, evtime);
event->time);
} }
return TRUE; return TRUE;
@ -1007,8 +1018,7 @@ meta_frame_left_click_event (MetaUIFrame *frame,
case META_FRAME_CONTROL_RESIZE_W: case META_FRAME_CONTROL_RESIZE_W:
meta_frames_try_grab_op (frame, meta_frames_try_grab_op (frame,
grab_op_from_resize_control (control), grab_op_from_resize_control (control),
event->x, event->y, x, y, evtime);
event->time);
return TRUE; return TRUE;
case META_FRAME_CONTROL_TITLE: case META_FRAME_CONTROL_TITLE:
@ -1019,8 +1029,7 @@ meta_frame_left_click_event (MetaUIFrame *frame,
{ {
meta_frames_try_grab_op (frame, meta_frames_try_grab_op (frame,
META_GRAB_OP_MOVING, META_GRAB_OP_MOVING,
event->x, event->y, x, y, evtime);
event->time);
} }
} }
@ -1036,21 +1045,26 @@ meta_frame_left_click_event (MetaUIFrame *frame,
} }
static gboolean static gboolean
handle_button_press_event (MetaUIFrame *frame, handle_press_event (MetaUIFrame *frame,
ClutterButtonEvent *event) const ClutterEvent *event)
{ {
MetaFrameControl control; MetaFrameControl control;
Display *display; Display *display;
guint evtime, button;
gfloat x, y;
display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
control = get_control (frame, event->x, event->y); evtime = clutter_event_get_time (event);
clutter_event_get_coords (event, &x, &y);
control = get_control (frame, x, y);
button = clutter_event_get_button (event);
/* don't do the rest of this if on client area */ /* don't do the rest of this if on client area */
if (control == META_FRAME_CONTROL_CLIENT_AREA) if (control == META_FRAME_CONTROL_CLIENT_AREA)
return FALSE; /* not on the frame, just passed through from client */ return FALSE; /* not on the frame, just passed through from client */
if (event->button == 1 && if (button == 1 &&
!(control == META_FRAME_CONTROL_MINIMIZE || !(control == META_FRAME_CONTROL_MINIMIZE ||
control == META_FRAME_CONTROL_DELETE || control == META_FRAME_CONTROL_DELETE ||
control == META_FRAME_CONTROL_MAXIMIZE)) control == META_FRAME_CONTROL_MAXIMIZE))
@ -1058,52 +1072,58 @@ handle_button_press_event (MetaUIFrame *frame,
meta_topic (META_DEBUG_FOCUS, meta_topic (META_DEBUG_FOCUS,
"Focusing window with frame 0x%lx due to button 1 press\n", "Focusing window with frame 0x%lx due to button 1 press\n",
frame->xwindow); frame->xwindow);
meta_window_focus (frame->meta_window, event->time); meta_window_focus (frame->meta_window, evtime);
} }
/* We want to shade even if we have a GrabOp, since we'll have a move grab /* We want to shade even if we have a GrabOp, since we'll have a move grab
* if we double click the titlebar. * if we double click the titlebar.
*/ */
if (control == META_FRAME_CONTROL_TITLE && if (control == META_FRAME_CONTROL_TITLE &&
event->button == 1 && button == 1 &&
event->click_count == 2) clutter_event_get_click_count (event) == 2)
{ {
meta_core_end_grab_op (display, event->time); meta_core_end_grab_op (display, evtime);
return meta_frame_double_click_event (frame, event); return meta_frame_double_click_event (frame, event);
} }
if (meta_core_get_grab_op (display) != META_GRAB_OP_NONE) if (meta_core_get_grab_op (display) != META_GRAB_OP_NONE)
return FALSE; /* already up to something */ return FALSE; /* already up to something */
frame->grab_button = event->button; frame->grab_button = button;
switch (event->button) switch (button)
{ {
case 1: case 1:
return meta_frame_left_click_event (frame, event); return meta_frame_left_click_event (frame, event);
case 2: case 2:
return meta_frame_middle_click_event (frame, event); return meta_frame_middle_click_event (frame, (ClutterButtonEvent *) event);
case 3: case 3:
return meta_frame_right_click_event (frame, event); return meta_frame_right_click_event (frame, (ClutterButtonEvent *) event);
default: default:
return FALSE; return FALSE;
} }
} }
static gboolean static gboolean
handle_button_release_event (MetaUIFrame *frame, handle_release_event (MetaUIFrame *frame,
ClutterButtonEvent *event) const ClutterEvent *event)
{ {
Display *display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); Display *display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
guint32 evtime, button;
gfloat x, y;
evtime = clutter_event_get_time (event);
clutter_event_get_coords (event, &x, &y);
button = clutter_event_get_button (event);
frame->frames->current_grab_op = META_GRAB_OP_NONE; frame->frames->current_grab_op = META_GRAB_OP_NONE;
meta_core_end_grab_op (display, event->time); meta_core_end_grab_op (display, evtime);
/* We only handle the releases we handled the presses for (things /* We only handle the releases we handled the presses for (things
* involving frame controls). Window ops that don't require a * involving frame controls). Window ops that don't require a
* frame are handled in the Xlib part of the code, display.c/window.c * frame are handled in the Xlib part of the code, display.c/window.c
*/ */
if (((int) event->button) == frame->grab_button && if (((int) button) == frame->grab_button &&
frame->button_state == META_BUTTON_STATE_PRESSED) frame->button_state == META_BUTTON_STATE_PRESSED)
{ {
switch (frame->prelit_control) switch (frame->prelit_control)
@ -1113,7 +1133,7 @@ handle_button_release_event (MetaUIFrame *frame,
break; break;
case META_FRAME_CONTROL_MAXIMIZE: case META_FRAME_CONTROL_MAXIMIZE:
/* Focus the window on the maximize */ /* Focus the window on the maximize */
meta_window_focus (frame->meta_window, event->time); meta_window_focus (frame->meta_window, evtime);
if (meta_prefs_get_raise_on_click ()) if (meta_prefs_get_raise_on_click ())
meta_window_raise (frame->meta_window); meta_window_raise (frame->meta_window);
meta_window_maximize (frame->meta_window, META_MAXIMIZE_BOTH); meta_window_maximize (frame->meta_window, META_MAXIMIZE_BOTH);
@ -1124,7 +1144,7 @@ handle_button_release_event (MetaUIFrame *frame,
meta_window_unmaximize (frame->meta_window, META_MAXIMIZE_BOTH); meta_window_unmaximize (frame->meta_window, META_MAXIMIZE_BOTH);
break; break;
case META_FRAME_CONTROL_DELETE: case META_FRAME_CONTROL_DELETE:
meta_window_delete (frame->meta_window, event->time); meta_window_delete (frame->meta_window, evtime);
break; break;
default: default:
break; break;
@ -1135,7 +1155,7 @@ handle_button_release_event (MetaUIFrame *frame,
* prelit so to let the user know that it can now be pressed. * prelit so to let the user know that it can now be pressed.
* :) * :)
*/ */
MetaFrameControl control = get_control (frame, event->x, event->y); MetaFrameControl control = get_control (frame, x, y);
meta_ui_frame_update_prelit_control (frame, control); meta_ui_frame_update_prelit_control (frame, control);
} }
@ -1236,13 +1256,19 @@ meta_ui_frame_update_prelit_control (MetaUIFrame *frame,
} }
static gboolean static gboolean
handle_motion_notify_event (MetaUIFrame *frame, handle_motion_event (MetaUIFrame *frame,
ClutterMotionEvent *event) const ClutterEvent *event)
{ {
MetaFrames *frames = frame->frames; MetaFrames *frames = frame->frames;
MetaFrameControl control; MetaFrameControl control;
ClutterModifierType modifiers;
guint32 evtime;
gfloat x, y;
control = get_control (frame, event->x, event->y); modifiers = clutter_event_get_state (event);
evtime = clutter_event_get_time (event);
clutter_event_get_coords (event, &x, &y);
control = get_control (frame, x, y);
if (frame->button_state == META_BUTTON_STATE_PRESSED) if (frame->button_state == META_BUTTON_STATE_PRESSED)
{ {
@ -1260,9 +1286,9 @@ handle_motion_notify_event (MetaUIFrame *frame,
meta_ui_frame_update_prelit_control (frame, control); meta_ui_frame_update_prelit_control (frame, control);
} }
if ((event->modifier_state & CLUTTER_BUTTON1_MASK) && if ((modifiers & CLUTTER_BUTTON1_MASK) &&
frames->current_grab_op != META_GRAB_OP_NONE) frames->current_grab_op != META_GRAB_OP_NONE)
meta_frames_retry_grab_op (frames, event->time); meta_frames_retry_grab_op (frames, evtime);
return TRUE; return TRUE;
} }
@ -1519,11 +1545,11 @@ meta_ui_frame_handle_event (MetaUIFrame *frame,
switch (event->any.type) switch (event->any.type)
{ {
case CLUTTER_BUTTON_PRESS: case CLUTTER_BUTTON_PRESS:
return handle_button_press_event (frame, (ClutterButtonEvent *) event); return handle_press_event (frame, event);
case CLUTTER_BUTTON_RELEASE: case CLUTTER_BUTTON_RELEASE:
return handle_button_release_event (frame, (ClutterButtonEvent *) event); return handle_release_event (frame, event);
case CLUTTER_MOTION: case CLUTTER_MOTION:
return handle_motion_notify_event (frame, (ClutterMotionEvent *) event); return handle_motion_event (frame, event);
case CLUTTER_ENTER: case CLUTTER_ENTER:
return handle_enter_notify_event (frame, (ClutterCrossingEvent *) event); return handle_enter_notify_event (frame, (ClutterCrossingEvent *) event);
case CLUTTER_LEAVE: case CLUTTER_LEAVE: