Esempio n. 1
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;
}
Esempio n. 2
0
PRIVATE void
draw_tray_icon(GdkWindow* wrapper, gpointer no_use, cairo_t* cr)
{
    static cairo_surface_t* left = NULL;
    static cairo_surface_t* right = NULL;
    if (left == NULL)
        left = cairo_image_surface_create_from_png(TRAY_LEFT_LINE_PATH);
    if (right == NULL)
        right = cairo_image_surface_create_from_png(TRAY_RIGHT_LINE_PATH);

    GdkWindow* icon = get_icon_window(wrapper);
    g_assert(GDK_IS_WINDOW(wrapper));
    if (!gdk_window_is_destroyed(icon)) {
        gboolean is_in = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(wrapper), "is_mouse_in"));
        int x = 0;
        int y = 0;
        gdk_window_get_geometry(wrapper, &x, &y, NULL, NULL); //gdk_window_get_position will get error value when dock is hidden!
        cairo_save(cr);
        if (wrapper == _deepin_tray || !is_in) {
            gdk_cairo_set_source_window(cr, icon, x, y);
            cairo_paint(cr);
        } else {
            if (cairo_surface_status(left) == CAIRO_STATUS_SUCCESS) {
                cairo_set_source_surface(cr, left, x - 4, y - 3);
                cairo_paint(cr);
            }
            gdk_cairo_set_source_window(cr, icon, x, y);
            cairo_paint(cr);
            if (cairo_surface_status(right) == CAIRO_STATUS_SUCCESS) {
                cairo_set_source_surface(cr, right, x + gdk_window_get_width(wrapper) + 2, y - 3);
                cairo_paint(cr);
            }
        }
        cairo_restore(cr);
    }
}