void aquire_hotkey(const char* widget_name, PrefsData *data) { gint resp, action; GtkWidget *diag = data->hotkey_dialog; action = (!strcmp(widget_name,"mute_eventbox"))? 0: (!strcmp(widget_name,"up_eventbox"))? 1: (!strcmp(widget_name,"down_eventbox"))? 2:-1; if (action < 0) { report_error("Invalid widget passed to aquire_hotkey: %s",widget_name); return; } switch(action) { case 0: gtk_label_set_text(GTK_LABEL(data->hotkey_key_label),_("Mute/Unmute")); break; case 1: gtk_label_set_text(GTK_LABEL(data->hotkey_key_label),_("Volume Up")); break; case 2: gtk_label_set_text(GTK_LABEL(data->hotkey_key_label),_("Volume Down")); break; default: break; } // grab keyboard if (G_LIKELY(gdk_keyboard_grab(gtk_widget_get_root_window(GTK_WIDGET(diag)), TRUE, GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS)) { resp = gtk_dialog_run(GTK_DIALOG(diag)); gdk_keyboard_ungrab (GDK_CURRENT_TIME); if (resp == GTK_RESPONSE_OK) { const gchar* key_name = gtk_label_get_text(GTK_LABEL(data->hotkey_key_label)); switch(action) { case 0: gtk_label_set_text(GTK_LABEL(data->mute_hotkey_label),key_name); break; case 1: gtk_label_set_text(GTK_LABEL(data->up_hotkey_label),key_name); break; case 2: gtk_label_set_text(GTK_LABEL(data->down_hotkey_label),key_name); break; default: break; } } } else report_error("%s", _("Could not grab the keyboard.")); gtk_widget_hide(diag); }
/* Grab the keyboard for maximum security */ static void grab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data) { if (!pinentry->grab) return; if (gdk_keyboard_grab (win->window, FALSE, gdk_event_get_time (event))) g_error ("could not grab keyboard"); }
static void grab_devices(GtkWidget *window) { gdk_pointer_grab(gtk_widget_get_window(window), TRUE, GDK_BUTTON_PRESS_MASK, NULL, NULL, GDK_CURRENT_TIME); gdk_keyboard_grab(gtk_widget_get_window(window), TRUE, GDK_CURRENT_TIME); }
static gboolean grab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data) { GdkGrabStatus status; #if GTK_CHECK_VERSION (3,0,0) GdkDevice *device; GdkDeviceManager *manager; GdkDisplay *display; GList *devices, *l; guint32 at; if (grabbed_device || !GRAB_KEYBOARD) return FALSE; display = gtk_widget_get_display (win); manager = gdk_display_get_device_manager (display); devices = gdk_device_manager_list_devices (manager, GDK_DEVICE_TYPE_MASTER); for (l = devices; l; l = g_list_next (l)) { device = l->data; if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) break; } g_list_free (devices); if (!device) { g_message ("couldn't find device to grab"); return FALSE; } at = gdk_event_get_time (event); status = gdk_device_grab (device, gtk_widget_get_window (win), GDK_OWNERSHIP_WINDOW, TRUE, GDK_KEY_PRESS | GDK_KEY_RELEASE, NULL, at); if (status == GDK_GRAB_SUCCESS) { grab_broken_id = g_signal_connect (win, "grab-broken-event", G_CALLBACK (on_grab_broken), NULL); gtk_device_grab_add (win, device, TRUE); grabbed_device = device; grabbed_at = at; } else { g_message ("could not grab keyboard: %d", (int)status); } #else if (!keyboard_grabbed && GRAB_KEYBOARD) { status = gdk_keyboard_grab (gtk_widget_get_window (win), FALSE, gdk_event_get_time (event)); if (status == GDK_GRAB_SUCCESS) { keyboard_grabbed = TRUE; } else { g_message ("could not grab keyboard: %d", (int)status); } } #endif /* Always return false, so event is handled elsewhere */ return FALSE; }
static gboolean grab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data) { #ifndef _DEBUG if (!g_object_get_data (G_OBJECT (win), "keyboard-grabbed")) if (gdk_keyboard_grab (gtk_widget_get_window (win), FALSE, gdk_event_get_time (event))) g_message ("could not grab keyboard"); g_object_set_data (G_OBJECT (win), "keyboard-grabbed", GINT_TO_POINTER (TRUE)); #endif return FALSE; }
static void gimp_pick_button_clicked (GtkButton *gtk_button) { GimpPickButton *button = GIMP_PICK_BUTTON (gtk_button); GtkWidget *widget; guint32 timestamp; if (! button->cursor) button->cursor = make_cursor (gtk_widget_get_display (GTK_WIDGET (gtk_button))); if (! button->grab_widget) { button->grab_widget = gtk_invisible_new (); gtk_widget_add_events (button->grab_widget, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK); gtk_widget_show (button->grab_widget); } widget = button->grab_widget; timestamp = gtk_get_current_event_time (); if (gdk_keyboard_grab (gtk_widget_get_window (widget), FALSE, timestamp) != GDK_GRAB_SUCCESS) { g_warning ("Failed to grab keyboard to do eyedropper"); return; } if (gdk_pointer_grab (gtk_widget_get_window (widget), FALSE, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK, NULL, button->cursor, timestamp) != GDK_GRAB_SUCCESS) { gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), timestamp); g_warning ("Failed to grab pointer to do eyedropper"); return; } gtk_grab_add (widget); g_signal_connect (widget, "button-press-event", G_CALLBACK (gimp_pick_button_mouse_press), button); g_signal_connect (widget, "key-press-event", G_CALLBACK (gimp_pick_button_key_press), button); }
void on_window_show( GtkWidget *w ) { while( gdk_keyboard_grab( w->window, FALSE, GDK_CURRENT_TIME ) != GDK_GRAB_SUCCESS ) { sleep( 0.1 ); } while( gdk_pointer_grab( w->window, TRUE, 0 ,NULL, NULL, GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS ) { sleep( 0.1 ); } }
static void popup_grab_notify(GtkWidget *popup, gboolean was_grabbed, GebrGuiToolButton *button) { GdkWindow *window = gtk_widget_get_window(popup); if (window && was_grabbed) { gdk_keyboard_grab(window, TRUE, GDK_CURRENT_TIME); gdk_pointer_grab(window, TRUE, GDK_BUTTON_PRESS_MASK, NULL, NULL, GDK_CURRENT_TIME); } }
void begin_key_grab(KeyGrabButton* self, gpointer v) { KeyGrabButton* b = KEYGRAB_BUTTON(self); b->popup = popup_new(GTK_WIDGET(self), _("Please press the new key combination"), FALSE); gtk_widget_add_events(GTK_WIDGET(b->popup), GDK_KEY_PRESS_MASK); gtk_widget_show_all(b->popup); gtk_window_present(GTK_WINDOW(b->popup)); b->handler = g_signal_connect(G_OBJECT(b->popup), "key-press-event", (GCallback)on_key_press_event, b); while (gdk_keyboard_grab(gtk_widget_get_window(GTK_WIDGET(b->popup)), FALSE, GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS) usleep(100); }
static gboolean gimp_context_help_idle_start (gpointer widget) { if (! gtk_grab_get_current ()) { GtkWidget *invisible; GdkCursor *cursor; GdkGrabStatus status; invisible = gtk_invisible_new_for_screen (gtk_widget_get_screen (widget)); gtk_widget_show (invisible); cursor = gdk_cursor_new_for_display (gtk_widget_get_display (invisible), GDK_QUESTION_ARROW); status = gdk_pointer_grab (gtk_widget_get_window (invisible), TRUE, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK, NULL, cursor, GDK_CURRENT_TIME); g_object_unref (cursor); if (status != GDK_GRAB_SUCCESS) { gtk_widget_destroy (invisible); return FALSE; } if (gdk_keyboard_grab (gtk_widget_get_window (invisible), TRUE, GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS) { gdk_display_pointer_ungrab (gtk_widget_get_display (invisible), GDK_CURRENT_TIME); gtk_widget_destroy (invisible); return FALSE; } gtk_grab_add (invisible); g_signal_connect (invisible, "button-press-event", G_CALLBACK (gimp_context_help_button_press), NULL); g_signal_connect (invisible, "key-press-event", G_CALLBACK (gimp_context_help_key_press), NULL); } return FALSE; }
static gboolean grab_keyboard_on_window (GdkWindow *window, guint32 activate_time) { GdkGrabStatus status; status = gdk_keyboard_grab (window, TRUE, activate_time); if (status == GDK_GRAB_SUCCESS) { return TRUE; } return FALSE; }
/* Grab the keyboard for maximum security */ static void grab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data) { if (! pinentry->grab) return; if (gdk_keyboard_grab (win->window, FALSE, gdk_event_get_time (event))) { g_critical ("could not grab keyboard"); grab_failed = 1; gtk_main_quit (); } }
/** * win: The GTK which's window should get the focus * event: The event that triggered grabbing * data: ignored * * Will grab the keyboard to the widget's window * * Returns TRUE if grabbed, FALSE else **/ static gboolean grab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data) { GdkGrabStatus status; if (!keyboard_grabbed && GRAB_KEYBOARD) { status = gdk_keyboard_grab (gtk_widget_get_window (win), FALSE, gdk_event_get_time (event)); if (status == GDK_GRAB_SUCCESS) { keyboard_grabbed = TRUE; } else { g_message ("could not grab keyboard: %d", (int)status); } } return FALSE; }
void ygtk_popup_window_popup (GtkWidget *widget, gint x, gint y, guint activate_time) { ygtk_popup_window_frame_position (widget, &x, &y); gtk_grab_add (widget); gtk_window_move (GTK_WINDOW (widget), x, y); gtk_widget_grab_focus (widget); gtk_widget_show (widget); // grab this with your teeth if (gdk_pointer_grab (gtk_widget_get_window(widget), TRUE, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, activate_time) == 0) if (gdk_keyboard_grab (gtk_widget_get_window(widget), TRUE, activate_time) != 0) gdk_pointer_ungrab (activate_time); }
static void window_show(GtkWidget *w, gpointer user_data) { /* grabbing might not succeed immediately... */ if (gdk_keyboard_grab(w->window, FALSE, GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS) { // never happened so far: /* ...wait a while and try again */ fprintf(stderr, "[bauhaus] failed to get keyboard focus for popup window!\n"); // struct timeval s; // s.tv_sec = 0; // s.tv_usec = 5000; // select(0, NULL, NULL, NULL, &s); // sched_yield(); } }
void gul_gestures_start (GulGestures *as, GtkWidget *widget, guint button, gint x, gint y) { static GdkCursor *cursor = NULL; GulGesturesPrivate *p = as->priv; g_object_ref (as); p->widget = g_object_ref (widget); p->button = button; /* get a new cursor, if necessary */ if (!cursor) cursor = gdk_cursor_new (GDK_PENCIL); /* grab the pointer as soon as possible, we might miss button_release * otherwise */ gdk_pointer_grab (widget->window, FALSE, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK, NULL, cursor, gtk_get_current_event_time ()); g_signal_connect (widget, "button_release_event", G_CALLBACK (gul_gestures_mouse_release_cb), as); /* init stroke */ stroke_init (); /* attach signals */ g_signal_connect (widget, "motion_notify_event", G_CALLBACK (gul_gestures_motion_cb), as); g_signal_connect (widget, "button_press_event", G_CALLBACK (gul_gestures_mouse_press_cb), as); g_signal_connect (widget, "key_press_event", G_CALLBACK (gul_gestures_key_press_cb), as); g_signal_connect (widget, "unmap-event", G_CALLBACK (gul_gestures_unmap_event_cb), as); gtk_grab_add (widget); gdk_keyboard_grab (widget->window, FALSE, gtk_get_current_event_time ()); p->start_x = x; p->start_y = y; p->started = TRUE; gul_gestures_start_autocancel (as); }
/* from GtkMenu sources */ gboolean popup_grab_on_window (GdkWindow * window, guint32 activate_time) { if ((gdk_pointer_grab (window, TRUE, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, activate_time) == 0)) { if (gdk_keyboard_grab (window, TRUE, activate_time) == 0) return TRUE; else { gdk_display_pointer_ungrab (gdk_drawable_get_display (window), activate_time); return FALSE; } } return FALSE; }
static gboolean popup_button_grab_on_window (GdkWindow *window, guint32 time) { if ((gdk_pointer_grab (window, TRUE, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, time) == 0)) { if (gdk_keyboard_grab (window, TRUE, time) == 0) return TRUE; else { gdk_pointer_ungrab (time); return FALSE; } } return FALSE; }
void eplay_load_image() { if (im) { gdk_imlib_kill_image(im); im = NULL; } if(!p[image_idx]) { im = gdk_imlib_load_image(image_names[image_idx]); } if (first) { w = org_w = im->rgb_width; h = org_h = im->rgb_height; win_x = (screen_x - w) / 2; win_y = (screen_y - h) / 2; attr.window_type = GDK_WINDOW_TEMP; attr.wclass = GDK_INPUT_OUTPUT; attr.event_mask = GDK_ALL_EVENTS_MASK; attr.x = attr.y = 0; attr.width = screen_x; attr.height = screen_y; parent = NULL; win = gdk_window_new(parent, &attr, ATTRIBUTES_MASK); gdk_window_show(win); gc = gdk_gc_new(win); first = 0; gdk_window_set_background(win, &color_bg); gdk_keyboard_grab(win, FALSE, CurrentTime); gdk_pointer_grab(win, FALSE, event_mask, NULL, cursor, CurrentTime); gdk_window_set_hints(win, win_x, win_y, w, h, w, h, GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE | GDK_HINT_POS); } /* gdk_imlib_free_pixmap(p[image_idx]); */ /* killing old pixmap */ if(!p[image_idx]) { gdk_imlib_render(im, w, h); /* Imlib render ... */ p[image_idx] = gdk_imlib_move_image(im); /* creating new */ } gdk_draw_pixmap(win, gc, p[image_idx], 0, 0, win_x, win_y, w, h); gdk_window_show(win); /* display image */ }
gint switch_fullscreen(GtkWidget *gl_area) { static GtkWidget *fullscreenwidget = NULL; if (!fullscreenwidget) { /* Grab keyboard and pointer so that user does not wander off the game window while in fullscreen mode. */ if (gdk_keyboard_grab(gl_area->window, FALSE, GDK_CURRENT_TIME) == 0) { if (gdk_pointer_grab(gl_area->window, FALSE, 0, NULL, NULL, GDK_CURRENT_TIME) == 0) { gtk_widget_grab_focus(gl_area); if (gtk_gl_area_make_current(GTK_GL_AREA(gl_area))) { if (XMesaSetFXmode((XMESA_FX_FULLSCREEN))) { fullscreenwidget = gl_area; return TRUE; } } gdk_pointer_ungrab(GDK_CURRENT_TIME); } gdk_keyboard_ungrab(GDK_CURRENT_TIME); } return FALSE; } if (fullscreenwidget == gl_area) { if (gtk_gl_area_make_current(GTK_GL_AREA(gl_area))) XMesaSetFXmode(XMESA_FX_WINDOW); gdk_keyboard_ungrab(GDK_CURRENT_TIME); gdk_pointer_ungrab(GDK_CURRENT_TIME); fullscreenwidget = NULL; return TRUE; } return FALSE; }
/** * Handles the 'activate' signal on the tray_icon, * usually opening the popup_window and grabbing pointer and keyboard. * * @param status_icon the object which received the signal * @param user_data user data set when the signal handler was connected */ void tray_icon_on_click(G_GNUC_UNUSED GtkStatusIcon *status_icon, G_GNUC_UNUSED gpointer user_data) { get_current_levels(); if (!gtk_widget_get_visible(GTK_WIDGET(popup_window))) { gtk_widget_show_now(popup_window); gtk_widget_grab_focus(vol_scale); #ifdef WITH_GTK3 GdkDevice *pointer_dev = gtk_get_current_event_device(); if (pointer_dev != NULL) { GdkDevice *keyboard_dev = gdk_device_get_associated_device(pointer_dev); if (gdk_device_grab(pointer_dev, gtk_widget_get_window(GTK_WIDGET(popup_window)), GDK_OWNERSHIP_NONE, TRUE, GDK_BUTTON_PRESS_MASK, NULL, GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS) g_warning("Could not grab %s\n", gdk_device_get_name(pointer_dev)); if (keyboard_dev != NULL) { if (gdk_device_grab(keyboard_dev, gtk_widget_get_window(GTK_WIDGET(popup_window)), GDK_OWNERSHIP_NONE, TRUE, GDK_KEY_PRESS_MASK, NULL, GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS) g_warning("Could not grab %s\n", gdk_device_get_name(keyboard_dev)); } } #else gdk_keyboard_grab(gtk_widget_get_window(popup_window), TRUE, GDK_CURRENT_TIME); gdk_pointer_grab(gtk_widget_get_window(popup_window), TRUE, GDK_BUTTON_PRESS_MASK, NULL, NULL, GDK_CURRENT_TIME); #endif } else { gtk_widget_hide(popup_window); } }
static void grab_window_toggled (GtkToggleButton *button, GtkWidget *widget) { if (gtk_toggle_button_get_active (button)) { int status; status = gdk_keyboard_grab (widget->window, FALSE, GDK_CURRENT_TIME); if (status != GDK_GRAB_SUCCESS) g_warning ("Could not grab keyboard! (%s)", grab_string (status)); } else { gdk_keyboard_ungrab (GDK_CURRENT_TIME); } }
void uni_nav_grab (UniNav * nav) { GtkWidget *preview = nav->preview; GdkWindow *window; gtk_grab_add (preview); GdkCursor *cursor = gdk_cursor_new (GDK_FLEUR); int mask = (GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_RELEASE_MASK | GDK_EXTENSION_EVENTS_ALL); window = gtk_widget_get_window (preview); gdk_pointer_grab (window, TRUE, mask, window, cursor, 0); gdk_cursor_unref (cursor); /* Capture keyboard events. */ gdk_keyboard_grab (window, TRUE, GDK_CURRENT_TIME); gtk_widget_grab_focus (preview); }
static void gtk_real_button_activate (GtkButton *button) { GtkWidget *widget = GTK_WIDGET (button); if (GTK_WIDGET_REALIZED (button) && !button->activate_timeout) { if (gdk_keyboard_grab (button->event_window, TRUE, gtk_get_current_event_time ()) == 0) { gtk_grab_add (widget); button->activate_timeout = g_timeout_add (ACTIVATE_TIMEOUT, button_activate_timeout, button); button->button_down = TRUE; gtk_button_update_state (button); gtk_widget_queue_draw (GTK_WIDGET (button)); } } }
/* Grabs the keyboard so that all events are passed to this application until * the keyboard is ungrabbed with gdk_keyboard_ungrab(). * This overrides any previous keyboard grab by this client. */ int clip_GDK_KEYBOARDGRAB(ClipMachine * ClipMachineMemory) { C_widget *cwin = _fetch_cw_arg(ClipMachineMemory); GdkWindow *win = NULL; gint owner_events = _clip_parl(ClipMachineMemory, 2); CHECKCWID(cwin, GTK_IS_WIDGET); CHECKOPT(2, LOGICAL_type_of_ClipVarType); if (cwin && cwin->widget) win = cwin->widget->window; gdk_keyboard_grab(win, owner_events, GDK_CURRENT_TIME); return 0; err: return 1; }
static void begin_area_grab (void) { if (grab_widget == NULL) { grab_widget = gtk_invisible_new (); gtk_widget_add_events (grab_widget, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK); gtk_widget_show (grab_widget); } if (gdk_keyboard_grab (gtk_widget_get_window (grab_widget), FALSE, gtk_get_current_event_time ()) != GDK_GRAB_SUCCESS) { g_warning ("Failed to grab keyboard to do eyedropper"); return; } if (gdk_pointer_grab (gtk_widget_get_window (grab_widget), FALSE, GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, gtk_get_current_event_time ()) != GDK_GRAB_SUCCESS) { gdk_keyboard_ungrab (GDK_CURRENT_TIME); g_warning ("Failed to grab pointer to do eyedropper"); return; } gtk_grab_add (grab_widget); g_signal_connect (grab_widget, "button_press_event", G_CALLBACK (mouse_press), NULL); g_signal_connect (grab_widget, "key_press_event", G_CALLBACK (key_press), NULL); }
static void gimp_popup_map (GtkWidget *widget) { GTK_WIDGET_CLASS (parent_class)->map (widget); /* grab with owner_events == TRUE so the popup's widgets can * receive events. we filter away events outside this toplevel * away in button_press() */ if (gdk_pointer_grab (gtk_widget_get_window (widget), TRUE, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, GDK_CURRENT_TIME) == 0) { if (gdk_keyboard_grab (gtk_widget_get_window (widget), TRUE, GDK_CURRENT_TIME) == 0) { gtk_grab_add (widget); g_signal_connect (widget, "grab-notify", G_CALLBACK (gimp_popup_grab_notify), widget); g_signal_connect (widget, "grab-broken-event", G_CALLBACK (gimp_popup_grab_broken_event), widget); return; } else { gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME); } } /* if we could not grab, destroy the popup instead of leaving it * around uncloseable. */ g_signal_emit (widget, popup_signals[CANCEL], 0); }
static gboolean popup_grab_on_window (GdkWindow *window, guint32 activate_time) { GdkEventMask emask = static_cast<GdkEventMask>(GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_ENTER_NOTIFY_MASK) ; if ((gdk_pointer_grab (window, FALSE,emask, NULL, NULL, activate_time) == 0)) { if (gdk_keyboard_grab (window, FALSE, activate_time) == 0) return TRUE; else { gdk_pointer_ungrab (activate_time); return FALSE; } } return FALSE; }
void VNCCanvas::grab_keyboard() { if(!keyboard_grabbed) { #ifdef __WXGTK__ // grab gdk_keyboard_grab(GetHandle()->window, True, GDK_CURRENT_TIME); // save previous settings GtkSettings *settings = gtk_settings_get_for_screen(gdk_screen_get_default()); g_object_get(settings, "gtk-enable-mnemonics", &saved_enable_mnemonics, NULL); g_object_get(settings, "gtk-enable-accels", &saved_enable_accels, NULL); g_object_get(settings, "gtk-menu-bar-accel", &saved_menubar_accel, NULL); // and disable keyboard shortcuts g_object_set(settings, "gtk-enable-mnemonics", false, NULL); g_object_set(settings, "gtk-enable-accels", false, NULL); g_object_set(settings, "gtk-menu-bar-accel", NULL, NULL); #endif keyboard_grabbed = true; wxLogDebug(wxT("VNCCanvas %p: grabbed keyboard"), this); } }
static gboolean gtk_scale_popup (GtkWidget *widget, GdkEvent *event, guint32 time) { GtkScaleButton *button; GtkScaleButtonPrivate *priv; GtkAdjustment *adj; gint x, y, m, dx, dy, sx, sy, startoff; gdouble v; GdkDisplay *display; GdkScreen *screen; button = GTK_SCALE_BUTTON (widget); priv = button->priv; adj = priv->adjustment; display = gtk_widget_get_display (widget); screen = gtk_widget_get_screen (widget); /* position roughly */ gtk_window_set_screen (GTK_WINDOW (priv->dock), screen); gdk_window_get_origin (widget->window, &x, &y); x += widget->allocation.x; y += widget->allocation.y; if (priv->orientation == GTK_ORIENTATION_VERTICAL) gtk_window_move (GTK_WINDOW (priv->dock), x, y - (SCALE_SIZE / 2)); else gtk_window_move (GTK_WINDOW (priv->dock), x - (SCALE_SIZE / 2), y); gtk_widget_show_all (priv->dock); gdk_window_get_origin (priv->dock->window, &dx, &dy); dx += priv->dock->allocation.x; dy += priv->dock->allocation.y; gdk_window_get_origin (priv->scale->window, &sx, &sy); sx += priv->scale->allocation.x; sy += priv->scale->allocation.y; priv->timeout = TRUE; /* position (needs widget to be shown already) */ v = gtk_scale_button_get_value (button) / (adj->upper - adj->lower); if (priv->orientation == GTK_ORIENTATION_VERTICAL) { startoff = sy - dy; x += (widget->allocation.width - priv->dock->allocation.width) / 2; y -= startoff; y -= GTK_RANGE (priv->scale)->min_slider_size / 2; m = priv->scale->allocation.height - GTK_RANGE (priv->scale)->min_slider_size; y -= m * (1.0 - v); } else { startoff = sx - dx; x -= startoff; y += (widget->allocation.height - priv->dock->allocation.height) / 2; x -= GTK_RANGE (priv->scale)->min_slider_size / 2; m = priv->scale->allocation.width - GTK_RANGE (priv->scale)->min_slider_size; x -= m * v; } /* Make sure the dock stays inside the monitor */ if (event->type == GDK_BUTTON_PRESS) { int monitor; GdkEventButton *button_event = (GdkEventButton *) event; GdkRectangle rect; GtkWidget *d; d = GTK_WIDGET (priv->dock); monitor = gdk_screen_get_monitor_at_point (screen, button_event->x_root, button_event->y_root); gdk_screen_get_monitor_geometry (screen, monitor, &rect); if (priv->orientation == GTK_ORIENTATION_VERTICAL) y += button_event->y; else x += button_event->x; if (y < rect.y) y = rect.y; else if (y + d->allocation.height > rect.height + rect.y) y = rect.y + rect.height - d->allocation.height; if (x < rect.x) x = rect.x; else if (x + d->allocation.width > rect.width + rect.x) x = rect.x + rect.width - d->allocation.width; } gtk_window_move (GTK_WINDOW (priv->dock), x, y); if (event->type == GDK_BUTTON_PRESS) GTK_WIDGET_CLASS (gtk_scale_button_parent_class)->button_press_event (widget, (GdkEventButton *) event); /* grab focus */ gtk_grab_add (priv->dock); if (gdk_pointer_grab (priv->dock->window, TRUE, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, time) != GDK_GRAB_SUCCESS) { gtk_grab_remove (priv->dock); gtk_widget_hide (priv->dock); return FALSE; } if (gdk_keyboard_grab (priv->dock->window, TRUE, time) != GDK_GRAB_SUCCESS) { gdk_display_pointer_ungrab (display, time); gtk_grab_remove (priv->dock); gtk_widget_hide (priv->dock); return FALSE; } gtk_widget_grab_focus (priv->dock); if (event->type == GDK_BUTTON_PRESS) { GdkEventButton *e; GdkEventButton *button_event = (GdkEventButton *) event; /* forward event to the slider */ e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event); e->window = priv->scale->window; /* position: the X position isn't relevant, halfway will work just fine. * The vertical position should be *exactly* in the middle of the slider * of the scale; if we don't do that correctly, it'll move from its current * position, which means a position change on-click, which is bad. */ if (priv->orientation == GTK_ORIENTATION_VERTICAL) { e->x = priv->scale->allocation.width / 2; m = priv->scale->allocation.height - GTK_RANGE (priv->scale)->min_slider_size; e->y = ((1.0 - v) * m) + GTK_RANGE (priv->scale)->min_slider_size / 2; } else { e->y = priv->scale->allocation.height / 2; m = priv->scale->allocation.width - GTK_RANGE (priv->scale)->min_slider_size; e->x = (v * m) + GTK_RANGE (priv->scale)->min_slider_size / 2; } gtk_widget_event (priv->scale, (GdkEvent *) e); e->window = button_event->window; gdk_event_free ((GdkEvent *) e); } gtk_widget_grab_focus (priv->scale); priv->pop_time = time; return TRUE; }