/* Stolen from GtkMenu */
static gboolean popup_grab_on_window(GdkWindow *window,
                                     GdkDevice *keyboard,
                                     GdkDevice *pointer,
                                     guint32  activate_time)
{
        if (keyboard &&
        gdk_device_grab(keyboard, window,
                         GDK_OWNERSHIP_WINDOW, TRUE,
                         GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
                         NULL, activate_time) != GDK_GRAB_SUCCESS)
        return FALSE;

        if (pointer &&
                gdk_device_grab(pointer, window,
                                GDK_OWNERSHIP_WINDOW, TRUE,
                                GDK_SMOOTH_SCROLL_MASK |
                                GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
                                GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
                                GDK_POINTER_MOTION_MASK,
                                NULL, activate_time) != GDK_GRAB_SUCCESS) {
                if (keyboard)
                        gdk_device_ungrab (keyboard, activate_time);

                return FALSE;
        }

  return TRUE;
}
示例#2
0
static gboolean
popup_grab_on_window (GtkWidget *widget, guint32 activate_time)
{
	GdkDeviceManager *manager;
	GdkDevice *pointer;
	GdkWindow *window;
	window = gtk_widget_get_window (widget);
	manager = gdk_display_get_device_manager (gtk_widget_get_display (widget));
	pointer = gdk_device_manager_get_client_pointer (manager);
        if (gdk_device_grab (pointer, window, GDK_OWNERSHIP_WINDOW, TRUE,
			     GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
			     GDK_POINTER_MOTION_MASK,
			     NULL, activate_time) == GDK_GRAB_SUCCESS) {
		GdkDevice *keyb;
		keyb = gdk_device_get_associated_device (pointer);
                if (gdk_device_grab (keyb, window, GDK_OWNERSHIP_WINDOW, TRUE,
				     GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK, NULL, activate_time) ==
		    GDK_GRAB_SUCCESS)
                         return TRUE;
                 else {
                        gdk_device_ungrab (pointer, activate_time);
			return FALSE;
		 }
        }
        return FALSE;
}
示例#3
0
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);

	GdkWindow *window = gtk_widget_get_window (widget);
	GdkDisplay *display = gdk_window_get_display (window);
	GdkDeviceManager *device_manager = gdk_display_get_device_manager (display);
	GdkDevice *pointer = gdk_device_manager_get_client_pointer (device_manager);

	// grab this with your teeth
	if (gdk_device_grab (pointer, window, GDK_OWNERSHIP_NONE, TRUE,
	        GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
	        NULL, activate_time) == 0) {
				GdkDevice *keyboard;
				keyboard = gdk_device_get_associated_device (pointer);
                if (gdk_device_grab (keyboard, window, GDK_OWNERSHIP_NONE, TRUE,
					GDK_KEY_PRESS | GDK_KEY_RELEASE, NULL, activate_time) != 0)
					gdk_device_ungrab (pointer, activate_time);
	}
}
示例#4
0
文件: marco-mag.c 项目: muesli4/marco
static void
begin_area_grab (void)
{
  GdkWindow *window;
  GdkDeviceManager *manager;
  GdkDevice *device;

  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);
    }

  window = gtk_widget_get_window (grab_widget);
  manager = gdk_display_get_device_manager (gdk_display_get_default ());
  device = gdk_device_manager_get_client_pointer (manager);

  if (gdk_device_grab (device,
                       window,
                       GDK_OWNERSHIP_NONE,
                       FALSE,
                       GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK,
                       NULL,
                       gtk_get_current_event_time ()) != GDK_GRAB_SUCCESS)
    {
      g_warning ("Failed to grab pointer to do eyedropper");
      return;
    }

  if (gdk_device_grab (gdk_device_get_associated_device (device),
                       window,
                       GDK_OWNERSHIP_NONE,
                       FALSE,
                       GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
                       NULL,
                       gtk_get_current_event_time ()) != GDK_GRAB_SUCCESS)
    {
      gdk_device_ungrab (device, gtk_get_current_event_time ());
      g_warning ("Failed to grab keyboard 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);
}
示例#5
0
void
panel_force_quit (GdkScreen *screen,
                  guint      time)
{
    GdkGrabStatus  status;
    GdkCursor     *cross;
    GtkWidget     *popup;
    GdkWindow     *root;
    GdkDisplay    *display;
    GdkDevice     *pointer;
    GdkDevice     *keyboard;
    GdkDeviceManager *device_manager;

    popup = display_popup_window (screen);

    root = gdk_screen_get_root_window (screen);

    gdk_window_add_filter (root, (GdkFilterFunc) popup_filter, popup);

    cross = gdk_cursor_new (GDK_CROSS);

    display = gdk_window_get_display (root);
    device_manager = gdk_display_get_device_manager (display);
    pointer = gdk_device_manager_get_client_pointer (device_manager);
    keyboard = gdk_device_get_associated_device (pointer);

    status = gdk_device_grab (pointer, root,
                              GDK_OWNERSHIP_NONE, FALSE,
                              GDK_BUTTON_PRESS_MASK,
                              cross, time);

    g_object_unref (cross);

    if (status != GDK_GRAB_SUCCESS) {
        g_warning ("Pointer grab failed\n");
        remove_popup (popup);
        return;
    }

    status = gdk_device_grab (keyboard, root,
                              GDK_OWNERSHIP_NONE, FALSE,
                              GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
                              NULL, time);
    if (status != GDK_GRAB_SUCCESS) {
        g_warning ("Keyboard grab failed\n");
        remove_popup (popup);
        return;
    }

    gdk_flush ();
}
示例#6
0
/*
 * gtk_bubble_window_grab:
 * @window: a #GtkBubbleWindow
 * @device: a master #GdkDevice
 * @activate_time: timestamp to perform the grab
 *
 * This function performs GDK and GTK+ grabs on @device and
 * its paired #GdkDevice. After this call all pointer/keyboard
 * events will be handled by @window.
 *
 * Calling this also brings in a #GtkMenu alike behavior, clicking
 * outside the #GtkBubbleWindow or pressing the Escape key will
 * popdown the menu by default.
 *
 * <note>
 *   If there was a previous grab, it will be undone before doing
 *   the requested grab.
 * </note>
 *
 * Returns: %TRUE if the grab was successful
 *
 * Since: 3.8
 */
gboolean
_gtk_bubble_window_grab (GtkBubbleWindow *window,
                         GdkDevice       *device,
                         guint32          activate_time)
{
  GtkBubbleWindowPrivate *priv;
  GdkDevice *other_device;
  GdkWindow *grab_window;
  GdkGrabStatus status;

  g_return_val_if_fail (GTK_IS_BUBBLE_WINDOW (window), FALSE);
  g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
  g_return_val_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER, FALSE);

  priv = window->priv;

  if (!priv->has_pointing_to ||
      gdk_window_is_destroyed (priv->relative_to))
    return FALSE;

  if (priv->device)
    _gtk_bubble_window_ungrab (window);

  gtk_widget_realize (GTK_WIDGET (window));
  grab_window = gtk_widget_get_window (GTK_WIDGET (window));
  other_device = gdk_device_get_associated_device (device);

  status = gdk_device_grab (device, grab_window,
                            GDK_OWNERSHIP_WINDOW, TRUE, GRAB_EVENT_MASK,
                            NULL, activate_time);

  if (status == GDK_GRAB_SUCCESS)
    {
      status = gdk_device_grab (other_device, grab_window,
                                GDK_OWNERSHIP_WINDOW, TRUE, GRAB_EVENT_MASK,
                                NULL, activate_time);

      /* Ungrab the first device on error */
      if (status != GDK_GRAB_SUCCESS)
        gdk_device_ungrab (device, activate_time);
    }

  if (status == GDK_GRAB_SUCCESS)
    {
      gtk_device_grab_add (GTK_WIDGET (window), device, TRUE);
      priv->device = device;
    }

  return status == GDK_GRAB_SUCCESS;
}
示例#7
0
static gboolean
on_widget_button_press (GtkWidget *widget,
			GdkEventButton *event,
			char *item_id)
{
  GdkDevice *device = gdk_event_get_device ((GdkEvent*) event);

  g_print ("%s received 'button-press' signal\n", item_id);

  if (device && strstr (item_id, "explicit"))
    {
      GdkGrabStatus status;
      GdkEventMask mask = GDK_BUTTON_PRESS_MASK
	| GDK_BUTTON_RELEASE_MASK
	| GDK_POINTER_MOTION_MASK
	| GDK_POINTER_MOTION_HINT_MASK
	| GDK_ENTER_NOTIFY_MASK
	| GDK_LEAVE_NOTIFY_MASK;

      status = gdk_device_grab (device, gtk_widget_get_window (widget),
				GDK_OWNERSHIP_NONE, FALSE, mask,
				NULL, event->time);
      if (status == GDK_GRAB_SUCCESS)
	g_print ("grabbed pointer\n");
      else
	g_print ("pointer grab failed\n");
    }

  return TRUE;
}
static gboolean
password_dialog_grab_keyboard (GtkWidget *widget,
    GdkEvent *event,
    gpointer user_data)
{
  EmpathyPasswordDialogPriv *priv = EMPATHY_PASSWORD_DIALOG (user_data)->priv;

  if (!priv->grabbing)
    {
      GdkDevice *device = gdk_event_get_device (event);

      if (device != NULL)
        {
          GdkGrabStatus status = gdk_device_grab (device,
              gtk_widget_get_window (widget),
              GDK_OWNERSHIP_WINDOW,
              FALSE,
              GDK_ALL_EVENTS_MASK,
              NULL,
              gdk_event_get_time (event));

          if (status != GDK_GRAB_SUCCESS)
            DEBUG ("Could not grab keyboard; grab status was %u", status);
          else
            priv->grabbing = TRUE;
        }
      else
        DEBUG ("Could not get the event device!");
    }

  return FALSE;
}
示例#9
0
文件: testsocket.c 项目: BYC/gtk
static void
grab_window_toggled (GtkToggleButton *button,
		     GtkWidget       *widget)
{
  GdkDevice *device = gtk_get_current_event_device ();

  if (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
    device = gdk_device_get_associated_device (device);

  if (gtk_toggle_button_get_active (button))
    {
      int status;

      status = gdk_device_grab (device,
                                gtk_widget_get_window (widget),
                                GDK_OWNERSHIP_NONE,
                                FALSE,
                                GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
                                NULL,
                                GDK_CURRENT_TIME);

      if (status != GDK_GRAB_SUCCESS)
	g_warning ("Could not grab keyboard!  (%s)", grab_string (status));

    } 
  else 
    {
      gdk_device_ungrab (device, GDK_CURRENT_TIME);
    }
}
示例#10
0
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;
}
示例#11
0
/* Asks the user to click on a window, then waits for them click
 * the mouse. When the mouse is released, returns the toplevel
 * window under the pointer, or NULL, if there is none.
 */
static GtkWidget *
query_for_toplevel (GdkScreen  *screen,
                    const char *prompt)
{
  GdkDisplay *display = gdk_screen_get_display (screen);
  GtkWidget *popup, *label, *frame;
  GdkCursor *cursor;
  GtkWidget *toplevel = NULL;

  popup = gtk_window_new (GTK_WINDOW_POPUP);
  gtk_window_set_screen (GTK_WINDOW (popup), screen);
  gtk_window_set_modal (GTK_WINDOW (popup), TRUE);
  gtk_window_set_position (GTK_WINDOW (popup), GTK_WIN_POS_CENTER);

  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
  gtk_container_add (GTK_CONTAINER (popup), frame);

  label = gtk_label_new (prompt);
  g_object_set (label, "margin", 10, NULL);
  gtk_container_add (GTK_CONTAINER (frame), label);

  gtk_widget_show_all (popup);
  cursor = gdk_cursor_new_from_name (display, "crosshair");

  if (gdk_device_grab (gtk_get_current_event_device (),
                       gtk_widget_get_window (popup),
                       GDK_OWNERSHIP_NONE,
                       FALSE,
                       GDK_BUTTON_RELEASE_MASK,
                       cursor,
                       GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS)
    {
      gboolean clicked = FALSE;

      g_signal_connect (popup, "button-release-event",
                        G_CALLBACK (button_release_event_cb), &clicked);

      /* Process events until clicked is set by button_release_event_cb.
       * We pass in may_block=TRUE since we want to wait if there
       * are no events currently.
       */
      while (!clicked)
        g_main_context_iteration (NULL, TRUE);

      toplevel = find_toplevel_at_pointer (gdk_screen_get_display (screen));
      if (toplevel == popup)
        toplevel = NULL;
    }

  g_object_unref (cursor);
  gtk_widget_destroy (popup);
  gdk_flush ();                 /* Really release the grab */

  return toplevel;
}
示例#12
0
/* Pulled from gtkcombobox.c */
static gboolean
popup_grab_on_window (GdkWindow *window,
                      GdkDevice *keyboard,
                      GdkDevice *pointer,
                      guint32    activate_time)
{

#if GTK_CHECK_VERSION(3,20,0)
    GdkDisplay *display = gdk_display_get_default ();
    GdkSeat *seat = gdk_display_get_default_seat (display);
    GdkEvent *event = gtk_get_current_event ();

    if (keyboard && gdk_seat_grab (seat, window, GDK_SEAT_CAPABILITY_KEYBOARD, TRUE, NULL,
                                   event, NULL, NULL) != GDK_GRAB_SUCCESS )
#else
    if (keyboard && gdk_device_grab (keyboard, window,
                                     GDK_OWNERSHIP_WINDOW, TRUE,
                                     GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
                                     NULL, activate_time) != GDK_GRAB_SUCCESS)
#endif
        return FALSE;

#if GTK_CHECK_VERSION(3,20,0)
    if (pointer && gdk_seat_grab (seat, window, GDK_SEAT_CAPABILITY_POINTER, TRUE, NULL,
                                  event, NULL, NULL) != GDK_GRAB_SUCCESS )
#else
    if (pointer && gdk_device_grab (pointer, window,
                                    GDK_OWNERSHIP_WINDOW, TRUE,
                                    GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
                                    GDK_POINTER_MOTION_MASK,
                                    NULL, activate_time) != GDK_GRAB_SUCCESS)
#endif
    {
        if (keyboard)
#if GTK_CHECK_VERSION(3,20,0)
            gdk_seat_ungrab (seat);
#else
            gdk_device_ungrab (keyboard, activate_time);
#endif
        return FALSE;
    }
    return TRUE;
}
示例#13
0
文件: main.c 项目: eaglexmw/pnmixer
/**
 * 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);
	}
}
示例#14
0
static void
grab_devices(GtkWidget *window)
{
	GdkDevice *pointer_dev;
	GdkDevice *keyboard_dev;
	GdkGrabStatus status;

	/* Grab the mouse */
	pointer_dev = gtk_get_current_event_device();
	if (pointer_dev == NULL) {
		WARN("Couldn't get current device");
                return;
	}

	status = gdk_device_grab(pointer_dev,
	                         gtk_widget_get_window(window),
	                         GDK_OWNERSHIP_NONE,
	                         TRUE,
	                         GDK_BUTTON_PRESS_MASK,
	                         NULL,
	                         GDK_CURRENT_TIME);
	if (status != GDK_GRAB_SUCCESS)
		WARN("Could not grab %s", gdk_device_get_name(pointer_dev));

	/* Grab the keyboard */
	keyboard_dev = gdk_device_get_associated_device(pointer_dev);
	if (keyboard_dev == NULL) {
		WARN("Couldn't get associated device");
                return;
        }

	status = gdk_device_grab(keyboard_dev,
	                         gtk_widget_get_window(window),
	                         GDK_OWNERSHIP_NONE,
	                         TRUE,
	                         GDK_KEY_PRESS_MASK,
	                         NULL, GDK_CURRENT_TIME);
	if (status != GDK_GRAB_SUCCESS)
		WARN("Could not grab %s", gdk_device_get_name(keyboard_dev));
}
示例#15
0
GdkGrabStatus XAP_gdk_pointer_grab(GdkWindow *window,
				   gboolean owner_events,
				   GdkEventMask event_mask,
				   GdkCursor *cursor,
				   guint32 time_)
{
	GdkDeviceManager *manager
		= gdk_display_get_device_manager(gdk_display_get_default());
	GdkDevice *device = gdk_device_manager_get_client_pointer (manager);
	return gdk_device_grab (device, window,
				GDK_OWNERSHIP_WINDOW,
				owner_events, event_mask,
				cursor, time_);
}
示例#16
0
// Now onto the device were the deprecated functions are to be
// with several line of code.
GdkGrabStatus XAP_gdk_keyboard_grab(GdkWindow *window,
				    gboolean owner_events,
				    guint32 time_)
{
	GdkDeviceManager *manager
		= gdk_display_get_device_manager(gdk_display_get_default());
	GdkDevice *device = gdk_device_manager_get_client_pointer (manager);

	return gdk_device_grab (gdk_device_get_associated_device(device),
				window,
				GDK_OWNERSHIP_WINDOW,
				owner_events,
				GDK_ALL_EVENTS_MASK,
				NULL,
				time_);
}
示例#17
0
文件: helper.c 项目: CannedFish/dde
JS_EXPORT_API
void guide_disable_keyboard()
{
    // gdk_keyboard_grab(gtk_widget_get_window(get_container()), FALSE, GDK_CURRENT_TIME);
    GdkWindow* window = gtk_widget_get_window(get_container());
    GdkDisplay* display = gdk_window_get_display(window);
    GdkDeviceManager* manager = gdk_display_get_device_manager(display);
    GList* devices = gdk_device_manager_list_devices(manager, GDK_DEVICE_TYPE_MASTER);
    GdkDevice* device = NULL;
    for (GList* dev = devices; dev != NULL; dev = dev->next) {
        device = GDK_DEVICE(dev->data);

        if (gdk_device_get_source(device) != GDK_SOURCE_KEYBOARD) {
            continue;
        }

        GdkGrabStatus res = gdk_device_grab(device,
                                            window,
                                            GDK_OWNERSHIP_NONE,
                                            FALSE,
                                            GDK_KEY_PRESS_MASK|GDK_KEY_RELEASE_MASK,
                                            NULL,
                                            GDK_CURRENT_TIME
                                           );
        switch (res) {
        case GDK_GRAB_ALREADY_GRABBED:
            g_warning("Grab falied, device %s is already grabbed.", gdk_device_get_name(device));
            break;
        case GDK_GRAB_INVALID_TIME:
            g_warning("Grab failed, the resource is grabbed more recently than the specified time.");
            break;
        case GDK_GRAB_NOT_VIEWABLE:
            g_warning("Grab falied, the window is not viewable.");
            break;
        case GDK_GRAB_FROZEN:
            g_warning("Grab falied, the resources is frozen.");
            break;
        case GDK_GRAB_SUCCESS:
            break;
        }
    }

    g_list_free(devices);
}
/* protected */ void
go_combo_box_popup_display (GOComboBox *combo_box)
{
	int x, y;

	g_return_if_fail (GO_COMBO_BOX (combo_box) != NULL);
	g_return_if_fail (combo_box->priv->popdown_container != NULL);

	if (combo_box->priv->torn_off) {
		/* To give the illusion that tearoff still displays the
		 * popup, we copy the image in the popup window to the
		 * background. Thus, it won't be blank after reparenting */
		go_combo_tearoff_bg_copy (combo_box);

		/* We force an unrealize here so that we don't trigger
		 * redrawing/ clearing code - we just want to reveal our
		 * backing pixmap.
		 */
		go_combo_popup_reparent (combo_box->priv->popup,
					  combo_box->priv->toplevel, TRUE);
	}

	go_combo_box_get_pos (combo_box, &x, &y);

	gtk_window_move (GTK_WINDOW (combo_box->priv->toplevel), x, y);
	gtk_widget_realize (combo_box->priv->popup);
	gtk_widget_show (combo_box->priv->popup);
	gtk_widget_realize (combo_box->priv->toplevel);
	gtk_widget_show (combo_box->priv->toplevel);

	gtk_widget_grab_focus (combo_box->priv->toplevel);
	do_focus_change (combo_box->priv->toplevel, TRUE);

	gtk_grab_add (combo_box->priv->toplevel);
	gdk_device_grab (gtk_get_current_event_device (),
	                 gtk_widget_get_window (combo_box->priv->toplevel),
	                 GDK_OWNERSHIP_APPLICATION, TRUE,
			 GDK_BUTTON_PRESS_MASK |
			 GDK_BUTTON_RELEASE_MASK |
			 GDK_POINTER_MOTION_MASK,
			 NULL, GDK_CURRENT_TIME);
	set_arrow_state (combo_box, TRUE);
}
示例#19
0
/**************************************************************************
  Popup a label with information about the tile, unit, city, when the user
  used the middle mouse button on the map.
**************************************************************************/
static void popit(GdkEventButton *event, struct tile *ptile)
{
  GtkWidget *p;
  static struct tmousepos mousepos;
  struct unit *punit;

  if (TILE_UNKNOWN != client_tile_get_known(ptile)) {
    p=gtk_window_new(GTK_WINDOW_POPUP);
    gtk_widget_set_app_paintable(p, TRUE);
    gtk_container_set_border_width(GTK_CONTAINER(p), 4);
    gtk_container_add(GTK_CONTAINER(p), gtk_label_new(popup_info_text(ptile)));

    punit = find_visible_unit(ptile);

    if (punit) {
      mapdeco_set_gotoroute(punit);
      if (punit->goto_tile) {
        mapdeco_set_crosshair(punit->goto_tile, TRUE);
      }
    }
    mapdeco_set_crosshair(ptile, TRUE);

    g_signal_connect(p, "destroy",
		     G_CALLBACK(popupinfo_popdown_callback), NULL);

    mousepos.x = event->x;
    mousepos.y = event->y;

    g_signal_connect(p, "size-allocate",
		     G_CALLBACK(popupinfo_positioning_callback), 
		     &mousepos);

    gtk_widget_show_all(p);
    gdk_device_grab(event->device, gtk_widget_get_window(p),
                    GDK_OWNERSHIP_NONE, TRUE, GDK_BUTTON_RELEASE_MASK, NULL,
                    event->time);
    gtk_grab_add(p);

    g_signal_connect_after(p, "button_release_event",
                           G_CALLBACK(popit_button_release), NULL);
  }
}
示例#20
0
void show_volume_scale(GdkRectangle *rect_or_null)
{
    // Actually show the volume scale
    do_show_volume_scale(rect_or_null);

    // Find the pointer device, if possible
    GdkDevice *device = gtk_get_current_event_device();
    if (device && gdk_device_get_source(device) == GDK_SOURCE_KEYBOARD)
        device = gdk_device_get_associated_device(device);
    if (!device) {
        g_printerr("Failed to find the pointer device\n");
        return;
    }

    // Grab it so we can hide the scale when the user clicks outside it
    g_signal_connect_after(G_OBJECT(window), "button_press_event", G_CALLBACK(on_pointer_press), NULL);
    gdk_device_grab(device, gtk_widget_get_window(window), GDK_OWNERSHIP_NONE,
            TRUE, GDK_BUTTON_PRESS_MASK, NULL, GDK_CURRENT_TIME);
    gdk_flush();
}
示例#21
0
void
gtk_inspector_on_inspect (GtkWidget          *button,
                          GtkInspectorWindow *iw)
{
  GdkDisplay *display;
  GdkDevice *device;
  GdkCursor *cursor;

  g_signal_connect (button, "event",
                    G_CALLBACK (property_query_event), iw);

  display = gtk_widget_get_display (button);
  cursor = gdk_cursor_new_for_display (display, GDK_CROSSHAIR);
  device = gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display));
  gdk_device_grab (device,
                   gtk_widget_get_window (GTK_WIDGET (button)),
                   GDK_OWNERSHIP_NONE, TRUE,
                   GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
                   cursor, GDK_CURRENT_TIME);
  g_object_unref (cursor);
  gtk_grab_add (GTK_WIDGET (button));

  gdk_window_lower (gtk_widget_get_window (GTK_WIDGET (iw)));
}
示例#22
0
static gboolean
gtk_window_button_press_callback(GtkWidget* widget, GdkEventButton* gdk_event, wxMiniFrame* win)
{
    if (gdk_event->window != gtk_widget_get_window(widget))
        return false;
    if (g_blockEventsOnDrag) return TRUE;
    if (g_blockEventsOnScroll) return TRUE;

    if (win->m_isDragging) return TRUE;

    int style = win->GetWindowStyle();

    int y = (int)gdk_event->y;
    int x = (int)gdk_event->x;

    if ((style & wxRESIZE_BORDER) &&
        (x > win->m_width-14) && (y > win->m_height-14))
    {
        GtkWidget *ancestor = gtk_widget_get_toplevel( widget );

        GdkWindow *source = gtk_widget_get_window(widget);

        int org_x = 0;
        int org_y = 0;
        gdk_window_get_origin( source, &org_x, &org_y );

        gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
                                  GDK_WINDOW_EDGE_SOUTH_EAST,
                                  1,
                                  org_x + x,
                                  org_y + y,
                                  0);

        return TRUE;
    }

    if (win->m_miniTitle && (style & wxCLOSE_BOX))
    {
        if ((y > 3) && (y < 19) && (x > win->m_width-19) && (x < win->m_width-3))
        {
            win->Close();
            return TRUE;
        }
    }

    if (y >= win->m_miniEdge + win->m_miniTitle)
        return true;

    gdk_window_raise(gtk_widget_get_window(win->m_widget));

    const GdkEventMask mask = GdkEventMask(
        GDK_BUTTON_PRESS_MASK |
        GDK_BUTTON_RELEASE_MASK |
        GDK_POINTER_MOTION_MASK |
        GDK_POINTER_MOTION_HINT_MASK |
        GDK_BUTTON_MOTION_MASK |
        GDK_BUTTON1_MOTION_MASK);
#ifdef __WXGTK3__
    gdk_device_grab(
        gdk_event->device, gdk_event->window, GDK_OWNERSHIP_NONE,
        false, mask, NULL, gdk_event->time);
#else
    gdk_pointer_grab(gdk_event->window, false, mask, NULL, NULL, gdk_event->time);
#endif

    win->m_diffX = x;
    win->m_diffY = y;
    win->m_oldX = 0;
    win->m_oldY = 0;

    win->m_isDragging = true;

    return TRUE;
}
示例#23
0
bool wxPopupTransientWindow::Show( bool show )
{
#ifdef __WXGTK__
    if (!show)
    {
#ifdef __WXGTK3__
        GdkDisplay* display = gtk_widget_get_display(m_widget);
#ifdef __WXGTK4__
        gdk_seat_ungrab(gdk_display_get_default_seat(display));
#else
        wxGCC_WARNING_SUPPRESS(deprecated-declarations)
        GdkDeviceManager* manager = gdk_display_get_device_manager(display);
        GdkDevice* device = gdk_device_manager_get_client_pointer(manager);
        gdk_device_ungrab(device, unsigned(GDK_CURRENT_TIME));
        wxGCC_WARNING_RESTORE()
#endif
#else
        gdk_pointer_ungrab( (guint32)GDK_CURRENT_TIME );
#endif

        gtk_grab_remove( m_widget );
    }
#endif

#ifdef __WXX11__
    if (!show)
    {
        XUngrabPointer( wxGlobalDisplay(), CurrentTime );
    }
#endif

#if defined( __WXMSW__ ) || defined( __WXMAC__)
    if (!show && m_child && m_child->HasCapture())
    {
        m_child->ReleaseMouse();
    }
#endif

    bool ret = wxPopupWindow::Show( show );

#ifdef __WXGTK__
    if (show)
    {
        gtk_grab_add( m_widget );

        GdkWindow* window = gtk_widget_get_window(m_widget);
#ifdef __WXGTK4__
        GdkDisplay* display = gdk_window_get_display(window);
        GdkSeat* seat = gdk_display_get_default_seat(display);
        gdk_seat_grab(seat, window, GDK_SEAT_CAPABILITY_POINTER, false, NULL, NULL, NULL, 0);
#else
        const GdkEventMask mask = GdkEventMask(
            GDK_BUTTON_PRESS_MASK |
            GDK_BUTTON_RELEASE_MASK |
            GDK_POINTER_MOTION_HINT_MASK |
            GDK_POINTER_MOTION_MASK);
#ifdef __WXGTK3__
        GdkDisplay* display = gdk_window_get_display(window);
        wxGCC_WARNING_SUPPRESS(deprecated-declarations)
        GdkDeviceManager* manager = gdk_display_get_device_manager(display);
        GdkDevice* device = gdk_device_manager_get_client_pointer(manager);
        gdk_device_grab(device, window,
            GDK_OWNERSHIP_NONE, true, mask, NULL, unsigned(GDK_CURRENT_TIME));
        wxGCC_WARNING_RESTORE()
#else
        gdk_pointer_grab( window, true,
                          mask,
                          NULL,
                          NULL,
                          (guint32)GDK_CURRENT_TIME );
#endif
#endif // !__WXGTK4__
    }
#endif

#ifdef __WXX11__
    if (show)
    {
        Window xwindow = (Window) m_clientWindow;

        /* int res =*/ XGrabPointer(wxGlobalDisplay(), xwindow,
            True,
            ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
            GrabModeAsync,
            GrabModeAsync,
            None,
            None,
            CurrentTime );
    }
#endif

#if defined( __WXMSW__ ) || defined( __WXMAC__)
    if (show && m_child)
    {
        // Assume that the mouse is outside the popup to begin with
        m_child->CaptureMouse();
    }
#endif

    return ret;
}
示例#24
0
static void
gtk_popup_button_popup_real (GtkPopupButton *popup_button, GdkDevice *device)
{
	GtkPopupButtonPrivate *priv = popup_button->priv;
	GtkAllocation button_allocation, dock_allocation;
	GdkScreen *screen;
	gint monitor_num;
	GdkRectangle monitor;
	GtkWidget *toplevel;
	GdkDevice *keyboard, *pointer;
	guint32 time;
	gint x, y;
	
	g_return_if_fail (GTK_IS_POPUP_BUTTON (popup_button));
	g_return_if_fail (GDK_IS_DEVICE (device));
	
	if (!gtk_widget_get_realized (GTK_WIDGET (popup_button)))
		return;
	
	if (gtk_widget_get_mapped (priv->dock))
		return;
	
	if (priv->grab_pointer && priv->grab_keyboard)
		return;
	
	time = gtk_get_current_event_time ();
	
	if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) {
		keyboard = device;
		pointer = gdk_device_get_associated_device (device);
	} else {
		pointer = device;
		keyboard = gdk_device_get_associated_device (device);
	}
	
	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (popup_button));
	if (GTK_IS_WINDOW (toplevel))
		gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
				GTK_WINDOW (priv->dock));
	
	/* positioning */
	gtk_widget_show (priv->dock);
	gtk_widget_get_allocation (GTK_WIDGET (popup_button), &button_allocation);
	gdk_window_get_root_coords (gtk_widget_get_window (GTK_WIDGET (popup_button)),
			button_allocation.x, button_allocation.y, &x, &y);
	gtk_widget_get_allocation (GTK_WIDGET (priv->dock), &dock_allocation);
	
	x = (x + button_allocation.width / 2) - (dock_allocation.width / 2);
	y = y - dock_allocation.height;
	
	GdkWindow *window = window = gtk_widget_get_window (GTK_WIDGET (popup_button));
	screen = gtk_widget_get_screen (GTK_WIDGET (priv->dock));
	monitor_num = gdk_screen_get_monitor_at_window (screen, window);
	gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
	
	if (x < monitor.x)
		x = monitor.x;
	else if (x + dock_allocation.width > monitor.x + monitor.width)
		x = monitor.x + monitor.width - dock_allocation.width;
	
	gtk_window_move (GTK_WINDOW (priv->dock), x, y);
	
	/* grabbing */
	gtk_widget_grab_focus (priv->dock);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (popup_button), TRUE);
	
	if (gdk_device_grab (pointer, gtk_widget_get_window (priv->dock),
			GDK_OWNERSHIP_WINDOW, TRUE,
			GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
			NULL, time) != GDK_GRAB_SUCCESS) {
		gtk_device_grab_remove (priv->dock, pointer);
		gtk_widget_hide (priv->dock);
		return;
	}
	
	if (gdk_device_grab (keyboard, gtk_widget_get_window (priv->dock),
			GDK_OWNERSHIP_WINDOW, TRUE,
			GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
			NULL, time) != GDK_GRAB_SUCCESS) {
		gdk_device_ungrab (pointer, time);
		gtk_device_grab_remove (priv->dock, pointer);
		gtk_widget_hide (priv->dock);
		return;
	}
	
	gtk_device_grab_add (priv->dock, pointer, TRUE);
	priv->grab_pointer = pointer;
	priv->grab_keyboard = keyboard;
}
static void
screenshot_select_area_x11_async (CallbackData *cb_data)
{
  GdkCursor *cursor;
  select_area_filter_data  data;
  GdkDeviceManager *manager;
  GdkDevice *pointer, *keyboard;
  GdkGrabStatus res;

  data.rect.x = 0;
  data.rect.y = 0;
  data.rect.width  = 0;
  data.rect.height = 0;
  data.button_pressed = FALSE;
  data.aborted = FALSE;
  data.window = create_select_window();

  g_signal_connect (data.window, "key-press-event", G_CALLBACK (select_area_key_press), &data);
  g_signal_connect (data.window, "button-press-event", G_CALLBACK (select_area_button_press), &data);
  g_signal_connect (data.window, "button-release-event", G_CALLBACK (select_area_button_release), &data);
  g_signal_connect (data.window, "motion-notify-event", G_CALLBACK (select_area_motion_notify), &data);

  cursor = gdk_cursor_new (GDK_CROSSHAIR);
  manager = gdk_display_get_device_manager (gdk_display_get_default ());
  pointer = gdk_device_manager_get_client_pointer (manager);
  keyboard = gdk_device_get_associated_device (pointer);

  res = gdk_device_grab (pointer, gtk_widget_get_window (data.window),
                         GDK_OWNERSHIP_NONE, FALSE,
                         GDK_POINTER_MOTION_MASK |
                         GDK_BUTTON_PRESS_MASK | 
                         GDK_BUTTON_RELEASE_MASK,
                         cursor, GDK_CURRENT_TIME);

  if (res != GDK_GRAB_SUCCESS)
    {
      g_object_unref (cursor);
      goto out;
    }

  res = gdk_device_grab (keyboard, gtk_widget_get_window (data.window),
                         GDK_OWNERSHIP_NONE, FALSE,
                         GDK_KEY_PRESS_MASK |
                         GDK_KEY_RELEASE_MASK,
                         NULL, GDK_CURRENT_TIME);
  if (res != GDK_GRAB_SUCCESS)
    {
      gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
      g_object_unref (cursor);
      goto out;
    }

  gtk_main ();

  gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
  gdk_device_ungrab (keyboard, GDK_CURRENT_TIME);

  gtk_widget_destroy (data.window);
  g_object_unref (cursor);

  gdk_flush ();

 out:
  cb_data->aborted = data.aborted;
  cb_data->rectangle = data.rect;

  /* FIXME: we should actually be emitting the callback When
   * the compositor has finished re-drawing, but there seems to be no easy
   * way to know that.
   */
  g_timeout_add (200, emit_select_callback_in_idle, cb_data);
}
示例#26
0
void acquire_grab (GromitData *data,
                   GdkDevice *dev)
{
    show_window (data);

    if(!dev) /* this means grab all */
    {
        GHashTableIter it;
        gpointer value;
        GromitDeviceData* devdata = NULL;
        g_hash_table_iter_init (&it, data->devdatatable);
        while (g_hash_table_iter_next (&it, NULL, &value))
        {
            GdkCursor *cursor;

            devdata = value;
            if(devdata->is_grabbed || gdk_device_get_device_type(devdata->device) == GDK_DEVICE_TYPE_SLAVE)
                continue;

            if(devdata->cur_context && devdata->cur_context->type == GROMIT_ERASER)
                cursor = data->erase_cursor;
            else
                cursor = data->paint_cursor;


            if(gdk_device_grab(devdata->device,
                               gtk_widget_get_window(data->win),
                               GDK_OWNERSHIP_NONE,
                               FALSE,
                               GROMIT_MOUSE_EVENTS,
                               cursor,
                               GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS)
            {
                /* this probably means the device table is outdated,
                e.g. this device doesn't exist anymore */
                g_printerr("Error grabbing Device '%s' while grabbing all, ignoring.\n",
                           gdk_device_get_name(devdata->device));
                continue;

            }

            devdata->is_grabbed = 1;
        }

        data->all_grabbed = 1;

        if(data->debug)
            g_printerr("DEBUG: Grabbed all Devices.\n");

        return;
    }

    GromitDeviceData *devdata =
        g_hash_table_lookup(data->devdatatable, dev);
    if (!devdata->is_grabbed)
    {
        GdkCursor *cursor;
        if(devdata->cur_context && devdata->cur_context->type == GROMIT_ERASER)
            cursor = data->erase_cursor;
        else
            cursor = data->paint_cursor;

        if(gdk_device_grab(devdata->device,
                           gtk_widget_get_window(data->win),
                           GDK_OWNERSHIP_NONE,
                           FALSE,
                           GROMIT_MOUSE_EVENTS,
                           cursor,
                           GDK_CURRENT_TIME) != GDK_GRAB_SUCCESS)
        {
            /* this probably means the device table is outdated,
               e.g. this device doesn't exist anymore */
            g_printerr("Error grabbing device '%s', rescanning device list.\n",
                       gdk_device_get_name(devdata->device));
            setup_input_devices(data);
            return;
        }

        devdata->is_grabbed = 1;

        if(data->debug)
            g_printerr("DEBUG: Grabbed Device '%s'.\n", gdk_device_get_name(devdata->device));
    }

}
示例#27
0
/**
 * gnm_cell_combo_view_popdown:
 * @sov: #SheetObjectView
 * @activate_time: event time
 *
 * Open the popup window associated with @sov
 **/
void
gnm_cell_combo_view_popdown (SheetObjectView *sov, guint32 activate_time)
{
	GocItem		   *view   = GOC_ITEM (sov);
	GnmPane		   *pane   = GNM_PANE (view->canvas);
	SheetControlGUI	   *scg    = pane->simple.scg;
	SheetObject	   *so     = sheet_object_view_get_so (sov);
	Sheet const	   *sheet  = sheet_object_get_sheet (so);
	GtkWidget *frame,  *popup, *list, *container;
	int root_x, root_y;
	gboolean 	make_buttons = FALSE;
	GtkTreePath	  *clip = NULL, *select = NULL;
	GtkWindow *toplevel = wbcg_toplevel (scg_wbcg (scg));
	GdkWindow *popup_window;
	GdkDevice *device;
	GnmRange const *merge;

	popup = gtk_window_new (GTK_WINDOW_POPUP);

	gtk_window_set_type_hint (GTK_WINDOW (popup), GDK_WINDOW_TYPE_HINT_COMBO);
	gtk_window_group_add_window (gtk_window_get_group (toplevel), GTK_WINDOW (popup));
	go_gtk_window_set_transient (toplevel, GTK_WINDOW (popup));
	gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
	gtk_window_set_decorated (GTK_WINDOW (popup), FALSE);
	gtk_window_set_screen (GTK_WINDOW (popup),
		gtk_widget_get_screen (GTK_WIDGET (toplevel)));

	list = ccombo_create_list (GNM_CCOMBO_VIEW (sov), so, &clip, &select, &make_buttons);

	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (list), FALSE);
	g_object_set_data (G_OBJECT (list), SOV_ID, sov);

	frame = gtk_frame_new (NULL);
	gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);

#if 0
	range_dump (&so->anchor.cell_bound, "");
	g_printerr (" : so = %p, view = %p\n", so, view);
#endif
	if (clip != NULL) {
		GtkWidget *sw = gtk_scrolled_window_new (
			gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (list)),
			gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (list)));
		gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
						GTK_POLICY_AUTOMATIC,
						GTK_POLICY_ALWAYS);
		g_object_set_data_full (G_OBJECT (list),
					"clip", clip,
					(GDestroyNotify)gtk_tree_path_free);

		gtk_container_add (GTK_CONTAINER (sw), list);

		/*
		 * Do the sizing in a realize handler as newer versions of
		 * gtk+ give us zero sizes until then.
		 */
		g_signal_connect_after (list, "realize",
					G_CALLBACK (cb_realize_treeview),
					sw);
		container = sw;
	} else
		container = list;

	if (make_buttons) {
		GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
		GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);

		GtkWidget *button;
		button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
		g_signal_connect_swapped (button, "clicked",
			G_CALLBACK (cb_ccombo_cancel_button), list);
		gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 6);
		button = gtk_button_new_from_stock (GTK_STOCK_OK);
		g_signal_connect_swapped (button, "clicked",
			G_CALLBACK (cb_ccombo_ok_button), list);
		gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 6);

		gtk_box_pack_start (GTK_BOX (vbox), container, FALSE, TRUE, 6);
		gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 6);
		container = vbox;
	}

	gtk_container_add (GTK_CONTAINER (frame), container);

	/* do the popup */
	gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (pane)),
			       &root_x, &root_y);
	if (sheet->text_is_rtl) {
		GtkAllocation pa;
		gtk_widget_get_allocation (GTK_WIDGET (pane), &pa);
		root_x += pa.width;
		root_x -= scg_colrow_distance_get (scg, TRUE,
			pane->first.col,
			so->anchor.cell_bound.start.col + 1);
	} else
		root_x += scg_colrow_distance_get (scg, TRUE,
			pane->first.col,
			so->anchor.cell_bound.start.col);
	merge = gnm_sheet_merge_is_corner (sheet, &(so->anchor.cell_bound.start));
	gtk_window_move (GTK_WINDOW (popup), root_x,
		root_y + scg_colrow_distance_get
			 (scg, FALSE,
			  pane->first.row,
			  so->anchor.cell_bound.start.row +
			  ((merge == NULL) ? 1 : range_height (merge))));

	gtk_container_add (GTK_CONTAINER (popup), frame);

	g_signal_connect (popup, "key_press_event",
		G_CALLBACK (cb_ccombo_key_press), list);
	g_signal_connect (popup, "button_press_event",
		G_CALLBACK (cb_ccombo_button_press), list);
	g_signal_connect_after (popup, "button_release_event",
		G_CALLBACK (cb_ccombo_button_release), list);
	g_signal_connect (list, "motion_notify_event",
		G_CALLBACK (cb_ccombo_list_motion), list);
	g_signal_connect (list, "button_press_event",
		G_CALLBACK (cb_ccombo_list_button_press), popup);

	gtk_widget_show_all (popup);

	/* after we show the window setup the selection (showing the list
	 * clears the selection) */
	if (select != NULL) {
		gtk_tree_selection_select_path (
			gtk_tree_view_get_selection (GTK_TREE_VIEW (list)),
			select);
		gtk_tree_view_set_cursor (GTK_TREE_VIEW (list),
			select, NULL, FALSE);
		gtk_tree_path_free (select);
	}

	gtk_widget_grab_focus (popup);
	gtk_widget_grab_focus (GTK_WIDGET (list));
	ccombo_focus_change (GTK_WIDGET (list), TRUE);

	popup_window = gtk_widget_get_window (popup);

	device = gtk_get_current_event_device ();
	if (0 == gdk_device_grab (device, popup_window,
	                          GDK_OWNERSHIP_APPLICATION, TRUE,
	                          GDK_BUTTON_PRESS_MASK |
	                          GDK_BUTTON_RELEASE_MASK |
	                          GDK_POINTER_MOTION_MASK,
	                          NULL, activate_time)) {
		if (0 == gdk_device_grab (gdk_device_get_associated_device (device),
		                          popup_window,
		                          GDK_OWNERSHIP_APPLICATION, TRUE,
		                          GDK_KEY_PRESS_MASK |
		                          GDK_KEY_RELEASE_MASK,
		                          NULL, activate_time))
			gtk_grab_add (popup);
		else
			gdk_device_ungrab (device, activate_time);
	}
}
static void
emoticon_tool_button_popup (EEmoticonToolButton *button)
{
	GtkToggleToolButton *tool_button;
	GdkWindow *window;
	gboolean grab_status;
	GdkDevice *device, *mouse, *keyboard;
	guint32 activate_time;

	device = gtk_get_current_event_device ();
	g_return_if_fail (device != NULL);

	if (!gtk_widget_get_realized (GTK_WIDGET (button)))
		return;

	if (button->priv->popup_shown)
		return;

	activate_time = gtk_get_current_event_time ();
	if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) {
		keyboard = device;
		mouse = gdk_device_get_associated_device (device);
	} else {
		keyboard = gdk_device_get_associated_device (device);
		mouse = device;
	}

	/* Position the window over the button. */
	emoticon_tool_button_reposition_window (button);

	/* Show the pop-up. */
	gtk_widget_show (button->priv->window);
	gtk_widget_grab_focus (button->priv->window);

	/* Activate the tool button. */
	tool_button = GTK_TOGGLE_TOOL_BUTTON (button);
	gtk_toggle_tool_button_set_active (tool_button, TRUE);

	/* Try to grab the pointer and keyboard. */
	window = gtk_widget_get_window (button->priv->window);
	grab_status = !keyboard ||
		gdk_device_grab (
			keyboard, window,
			GDK_OWNERSHIP_WINDOW, TRUE,
			GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
			NULL, activate_time) == GDK_GRAB_SUCCESS;
	if (grab_status) {
		grab_status = !mouse ||
			gdk_device_grab (mouse, window,
				GDK_OWNERSHIP_WINDOW, TRUE,
				GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
				NULL, activate_time) == GDK_GRAB_SUCCESS;
		if (!grab_status && keyboard)
			gdk_device_ungrab (keyboard, activate_time);
	}

	if (grab_status) {
		gtk_device_grab_add (button->priv->window, mouse, TRUE);
		button->priv->grab_keyboard = keyboard;
		button->priv->grab_mouse = mouse;
	} else {
		gtk_widget_hide (button->priv->window);
	}
}
示例#29
0
/* This is a _horrible_ hack to have this here. This needs to be added to the
 * GTK+ menuing code in some manner.
 */
static void  
drag_end_menu_cb (GtkWidget *widget, GdkDragContext     *context)
{
  GtkWidget *xgrab_shell;
  GtkWidget *parent;

  /* Find the last viewable ancestor, and make an X grab on it
   */
  parent = gtk_widget_get_parent (widget);
  xgrab_shell = NULL;

  /* FIXME: workaround for a possible gtk+ bug
   *    See bugs #92085(gtk+) and #91184(panel) for details.
   */
  g_object_set (widget, "has-tooltip", TRUE, NULL);

  while (parent)
    {
      gboolean viewable = TRUE;
      GtkWidget *tmp = parent;
      
      while (tmp)
	{
	  if (!gtk_widget_get_mapped (tmp))
	    {
	      viewable = FALSE;
	      break;
	    }
	  tmp = gtk_widget_get_parent (tmp);
	}
      
      if (viewable)
	xgrab_shell = parent;
      
      parent = gtk_menu_shell_get_parent_shell (GTK_MENU_SHELL (parent));
    }

  if (xgrab_shell)
    {
      gboolean      status;
      GdkDisplay    *display;
      GdkDevice     *pointer;
      GdkDevice     *keyboard;
      GdkDeviceManager *device_manager;
      GdkWindow *window = gtk_widget_get_window (xgrab_shell);
      GdkCursor *cursor = gdk_cursor_new_for_display (gdk_display_get_default (),
                                                      GDK_ARROW);

      display = gdk_window_get_display (window);
      device_manager = gdk_display_get_device_manager (display);
      pointer = gdk_device_manager_get_client_pointer (device_manager);
      keyboard = gdk_device_get_associated_device (pointer);

      /* FIXMEgpoo: Not sure if report to GDK_OWNERSHIP_WINDOW
	            or GDK_OWNERSHIP_APPLICATION. Idem for the
                    keyboard below */
      status = gdk_device_grab (pointer, window,
                                GDK_OWNERSHIP_WINDOW, TRUE,
                                GDK_BUTTON_PRESS_MASK
                                | GDK_BUTTON_RELEASE_MASK
                                | GDK_ENTER_NOTIFY_MASK
                                | GDK_LEAVE_NOTIFY_MASK
                                | GDK_POINTER_MOTION_MASK,
                                cursor, GDK_CURRENT_TIME);

      if (!status)
	{
	  if (gdk_device_grab (keyboard, window,
			       GDK_OWNERSHIP_WINDOW, TRUE,
			       GDK_KEY_PRESS | GDK_KEY_RELEASE,
			       NULL, GDK_CURRENT_TIME) == GDK_GRAB_SUCCESS)
	    {
	    /* FIXMEgpoo: We need either accessors or a workaround to grab
	       the focus */
#if 0
	     GTK_MENU_SHELL (xgrab_shell)->GSEAL(have_xgrab) = TRUE;
#endif
	    }
	  else
	    {
	      gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
	    }
	}

      g_object_unref (cursor);
    }
}
示例#30
0
static gint
process_event (GtkWidget *widget, GdkEvent *event, gpointer data G_GNUC_UNUSED)
{
  static GtkWidget *original_widget = NULL;
  static GdkCursor *cursor = NULL;

  switch (event->type) {
    case GDK_BUTTON_PRESS:
		if (event->button.button != gstroke_get_mouse_button()) {
			/* Similar to the bug below catch when any other button is
			 * clicked after the middle button is clicked (but possibly
			 * not released)
			 */
			gstroke_cancel(event);
			original_widget = NULL;
			break;
		}

      original_widget = widget; /* remeber the widget where
                                   the stroke started */

      gstroke_invisible_window_init (widget);

      record_stroke_segment (widget);

	  if (cursor == NULL)
		  cursor = gdk_cursor_new(GDK_PENCIL);

      gdk_device_grab(gdk_event_get_device(event),
                      gtk_widget_get_window(widget), GDK_OWNERSHIP_WINDOW,
                      FALSE, GDK_BUTTON_RELEASE_MASK, cursor,
                      event->button.time);
      timer_id = g_timeout_add (GSTROKE_TIMEOUT_DURATION,
				  gstroke_timeout, widget);
      return TRUE;

    case GDK_BUTTON_RELEASE:
      if ((event->button.button != gstroke_get_mouse_button())
	  || (original_widget == NULL)) {

		/* Nice bug when you hold down one button and press another. */
		/* We'll just cancel the gesture instead. */
		gstroke_cancel(event);
		original_widget = NULL;
		break;
	  }

      last_mouse_position.invalid = TRUE;
      original_widget = NULL;
      g_source_remove (timer_id);
      gdk_device_ungrab(gdk_event_get_device(event), event->button.time);
      timer_id = 0;

      {
	char result[GSTROKE_MAX_SEQUENCE];
	struct gstroke_metrics *metrics;

	metrics = (struct gstroke_metrics *)g_object_get_data(G_OBJECT (widget),
														  GSTROKE_METRICS);
		if (gstroke_draw_strokes()) {
			/* get rid of the invisible stroke window */
			XUnmapWindow (gstroke_disp, gstroke_window);
			XFlush (gstroke_disp);
		}

	_gstroke_canonical (result, metrics);
	gstroke_execute (widget, result);
      }
      return FALSE;

    default:
      break;
  }

  return FALSE;
}