Skip to content

Commit

Permalink
Handle deprecation of gtk_menu_popup
Browse files Browse the repository at this point in the history
GTK+ 3.22 deprecates gtk_menu_popup in favour of various
gtk_menu_popup_at_* functions.  gtk_menu_popup_at_pointer seems most
appropriate, but that requires being able to pass it a GdkEvent rather
than just some elements of it.  In order to achieve that, I've
rearranged the scroll_event shim to construct a real GdkEventButton and
pass that down to button_internal.
  • Loading branch information
cjwatson authored and sgtatham committed Mar 7, 2017
1 parent 2d0b2e9 commit 6422197
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions unix/gtkwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1817,56 +1817,58 @@ gboolean scroll_internal(struct gui_data *inst, gdouble delta, guint state,
}
#endif

gboolean button_internal(struct gui_data *inst, guint32 timestamp,
GdkEventType type, guint ebutton, guint state,
gdouble ex, gdouble ey)
static gboolean button_internal(struct gui_data *inst, GdkEventButton *event)
{
int shift, ctrl, alt, x, y, button, act, raw_mouse_mode;

/* Remember the timestamp. */
inst->input_event_time = timestamp;
inst->input_event_time = event->time;

show_mouseptr(inst, 1);

shift = state & GDK_SHIFT_MASK;
ctrl = state & GDK_CONTROL_MASK;
alt = state & inst->meta_mod_mask;
shift = event->state & GDK_SHIFT_MASK;
ctrl = event->state & GDK_CONTROL_MASK;
alt = event->state & inst->meta_mod_mask;

raw_mouse_mode =
send_raw_mouse && !(shift && conf_get_int(inst->conf,
CONF_mouse_override));

if (!raw_mouse_mode) {
if (ebutton == 4 && type == GDK_BUTTON_PRESS) {
if (event->button == 4 && event->type == GDK_BUTTON_PRESS) {
term_scroll(inst->term, 0, -SCROLL_INCREMENT_LINES);
return TRUE;
}
if (ebutton == 5 && type == GDK_BUTTON_PRESS) {
if (event->button == 5 && event->type == GDK_BUTTON_PRESS) {
term_scroll(inst->term, 0, +SCROLL_INCREMENT_LINES);
return TRUE;
}
}

if (ebutton == 3 && ctrl) {
if (event->button == 3 && ctrl) {
#if GTK_CHECK_VERSION(3,22,0)
gtk_menu_popup_at_pointer(GTK_MENU(inst->menu), (GdkEvent *)event);
#else
gtk_menu_popup(GTK_MENU(inst->menu), NULL, NULL, NULL, NULL,
ebutton, timestamp);
event->button, event->time);
#endif
return TRUE;
}

if (ebutton == 1)
if (event->button == 1)
button = MBT_LEFT;
else if (ebutton == 2)
else if (event->button == 2)
button = MBT_MIDDLE;
else if (ebutton == 3)
else if (event->button == 3)
button = MBT_RIGHT;
else if (ebutton == 4)
else if (event->button == 4)
button = MBT_WHEEL_UP;
else if (ebutton == 5)
else if (event->button == 5)
button = MBT_WHEEL_DOWN;
else
return FALSE; /* don't even know what button! */

switch (type) {
switch (event->type) {
case GDK_BUTTON_PRESS: act = MA_CLICK; break;
case GDK_BUTTON_RELEASE: act = MA_RELEASE; break;
case GDK_2BUTTON_PRESS: act = MA_2CLK; break;
Expand All @@ -1877,8 +1879,8 @@ gboolean button_internal(struct gui_data *inst, guint32 timestamp,
if (raw_mouse_mode && act != MA_CLICK && act != MA_RELEASE)
return TRUE; /* we ignore these in raw mouse mode */

x = (ex - inst->window_border) / inst->font_width;
y = (ey - inst->window_border) / inst->font_height;
x = (event->x - inst->window_border) / inst->font_width;
y = (event->y - inst->window_border) / inst->font_height;

term_mouse(inst->term, button, translate_button(button), act,
x, y, shift, ctrl, alt);
Expand All @@ -1889,8 +1891,7 @@ gboolean button_internal(struct gui_data *inst, guint32 timestamp,
gboolean button_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
struct gui_data *inst = (struct gui_data *)data;
return button_internal(inst, event->time, event->type, event->button,
event->state, event->x, event->y);
return button_internal(inst, event);
}

#if GTK_CHECK_VERSION(2,0,0)
Expand All @@ -1911,15 +1912,31 @@ gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data)
return FALSE;
#else
guint button;
GdkEventButton *event_button;
gboolean ret;

if (event->direction == GDK_SCROLL_UP)
button = 4;
else if (event->direction == GDK_SCROLL_DOWN)
button = 5;
else
return FALSE;

return button_internal(inst, event->time, GDK_BUTTON_PRESS,
button, event->state, event->x, event->y);
event_button = (GdkEventButton *)gdk_event_new(GDK_BUTTON_PRESS);
event_button->window = event->window;
event_button->send_event = event->send_event;
event_button->time = event->time;
event_button->x = event->x;
event_button->y = event->y;
event_button->axes = NULL;
event_button->state = event->state;
event_button->button = button;
event_button->device = event->device;
event_button->x_root = event->x_root;
event_button->y_root = event->y_root;
ret = button_internal(inst, event_button);
gdk_event_free(event_button);
return ret;
#endif
}
#endif
Expand Down

0 comments on commit 6422197

Please sign in to comment.