예제 #1
0
void
gdk_directfb_pointer_ungrab (guint32  time,
                             gboolean implicit_grab)
{
  GdkWindow             *toplevel;
  GdkWindow             *mousewin;
  GdkWindow             *old_grab_window;
  GdkWindowImplDirectFB *impl;

  if (implicit_grab && !_gdk_directfb_pointer_implicit_grab)
    return;

  if (!_gdk_directfb_pointer_grab_window)
    return;

  toplevel =
    gdk_directfb_window_find_toplevel (_gdk_directfb_pointer_grab_window);
  impl = GDK_WINDOW_IMPL_DIRECTFB (GDK_WINDOW_OBJECT (toplevel)->impl);

  if (impl->window)
    impl->window->UngrabPointer (impl->window);

  if (_gdk_directfb_pointer_grab_confine)
    {
      g_object_unref (_gdk_directfb_pointer_grab_confine);
      _gdk_directfb_pointer_grab_confine = NULL;
    }

  if (_gdk_directfb_pointer_grab_cursor)
    {
      gdk_cursor_unref (_gdk_directfb_pointer_grab_cursor);
      _gdk_directfb_pointer_grab_cursor = NULL;
    }

  old_grab_window = _gdk_directfb_pointer_grab_window;

  _gdk_directfb_pointer_grab_window   = NULL;
  _gdk_directfb_pointer_implicit_grab = FALSE;

  mousewin = gdk_window_at_pointer (NULL, NULL);
  gdk_directfb_window_send_crossing_events (old_grab_window,
                                            mousewin,
                                            GDK_CROSSING_UNGRAB);
  g_object_unref (old_grab_window);
}
예제 #2
0
파일: main.c 프로젝트: eaglexmw/pnmixer
/**
 * Hides the volume popup_window, connected via the signals
 * button-press-event, key-press-event and grab-broken-event.
 *
 * @param widget the object which received the signal
 * @param event the GdkEventButton which triggered the signal
 * @param user_data user data set when the signal handler was connected
 * @return TRUE to stop other handlers from being invoked for the evend,
 * FALSE to propagate the event further
 */
gboolean
hide_me(G_GNUC_UNUSED GtkWidget *widget,
		GdkEvent *event, G_GNUC_UNUSED gpointer user_data)
{
#ifdef WITH_GTK3
	GdkDevice *device = gtk_get_current_event_device();
#endif
	gint x, y;

	switch (event->type) {
	/* If a click happens outside of the popup, hide it */
	case GDK_BUTTON_PRESS:
		if (
#ifdef WITH_GTK3
			!gdk_device_get_window_at_position(device, &x, &y)
#else
			!gdk_window_at_pointer(&x, &y)
#endif
		)
			gtk_widget_hide(popup_window);
		break;

	/* If 'Esc' is pressed, hide popup */
	case GDK_KEY_PRESS:
		if (event->key.keyval == GDK_KEY_Escape) {
			gtk_widget_hide(popup_window);
		}
		break;

	/* Broken grab, hide popup */
	case GDK_GRAB_BROKEN:
		gtk_widget_hide(popup_window);
		break;

	/* Unhandle event, do nothing */
	default:
		break;
	}

	return FALSE;
}
예제 #3
0
파일: caja-notebook.c 프로젝트: Exalm/caja
/* FIXME remove when gtknotebook's func for this becomes public, bug #.... */
static CajaNotebook *
find_notebook_at_pointer (gint abs_x, gint abs_y)
{
#if GTK_CHECK_VERSION(3, 0, 0)
    GdkDeviceManager *manager;
    GdkDevice *pointer;
#endif
    GdkWindow *win_at_pointer, *toplevel_win;
    gpointer toplevel = NULL;
    gint x, y;

    /* FIXME multi-head */
#if GTK_CHECK_VERSION(3, 0, 0)
    manager = gdk_display_get_device_manager (gdk_display_get_default ());
    pointer = gdk_device_manager_get_client_pointer (manager);
    win_at_pointer = gdk_device_get_window_at_position (pointer, &x, &y);
#else
    win_at_pointer = gdk_window_at_pointer (&x, &y);
#endif

    if (win_at_pointer == NULL)
    {
        /* We are outside all windows containing a notebook */
        return NULL;
    }

    toplevel_win = gdk_window_get_toplevel (win_at_pointer);

    /* get the GtkWidget which owns the toplevel GdkWindow */
    gdk_window_get_user_data (toplevel_win, &toplevel);

    /* toplevel should be an CajaWindow */
    if (toplevel != NULL && CAJA_IS_NAVIGATION_WINDOW (toplevel))
    {
        return CAJA_NOTEBOOK (CAJA_NAVIGATION_WINDOW_PANE (CAJA_WINDOW (toplevel)->details->active_pane)->notebook);
    }

    return NULL;
}
예제 #4
0
/**
 * Handles 'button-press-event', 'key-press-event' and 'grab-broken-event' signals,
 * on the GtkWindow. Used to hide the volume popup window.
 *
 * @param widget the object which received the signal.
 * @param event the GdkEvent which triggered this signal.
 * @param window user data set when the signal handler was connected.
 * @return TRUE to stop other handlers from being invoked for the event.
 * FALSE to propagate the event further.
 */
gboolean
on_popup_window_event(G_GNUC_UNUSED GtkWidget *widget, GdkEvent *event,
                      PopupWindow *window)
{
	switch (event->type) {

	/* If a click happens outside of the popup, hide it */
	case GDK_BUTTON_PRESS: {
		gint x, y;
#ifdef WITH_GTK3
		GdkDevice *device = gtk_get_current_event_device();

		if (!gdk_device_get_window_at_position(device, &x, &y))
#else
		if (!gdk_window_at_pointer(&x, &y))
#endif
			popup_window_hide(window);

		break;
	}

	/* If 'Esc' is pressed, hide popup */
	case GDK_KEY_PRESS:
		if (event->key.keyval == GDK_KEY_Escape)
			popup_window_hide(window);
		break;

	/* Broken grab, hide popup */
	case GDK_GRAB_BROKEN:
		popup_window_hide(window);
		break;

	/* Unhandle event, do nothing */
	default:
		break;
	}

	return FALSE;
}
예제 #5
0
static void
gdl_dock_master_drag_motion (GdlDockItem *item, 
                             gint         root_x, 
                             gint         root_y,
                             gpointer     data)
{
    GdlDockMaster  *master;
    GdlDockRequest  my_request, *request;
    GdkWindow      *window;
    gint            win_x, win_y;
    gint            x, y;
    GdlDock        *dock = NULL;
    gboolean        may_dock = FALSE;
    
    g_return_if_fail (item != NULL && data != NULL);

    master = GDL_DOCK_MASTER (data);
    request = master->_priv->drag_request;

    g_return_if_fail (GDL_DOCK_OBJECT (item) == request->applicant);
    
    my_request = *request;

    /* first look under the pointer */
    window = gdk_window_at_pointer (&win_x, &win_y);
    if (window) {
        GtkWidget *widget;
        /* ok, now get the widget who owns that window and see if we can
           get to a GdlDock by walking up the hierarchy */
        gdk_window_get_user_data (window, (gpointer) &widget);
        if (GTK_IS_WIDGET (widget)) {
            while (widget && (!GDL_IS_DOCK (widget) || 
	           GDL_DOCK_OBJECT_GET_MASTER (widget) != master))
                widget = widget->parent;
            if (widget) {
                gint win_w, win_h;
                
                /* verify that the pointer is still in that dock
                   (the user could have moved it) */
                gdk_window_get_geometry (widget->window,
                                         NULL, NULL, &win_w, &win_h, NULL);
                gdk_window_get_origin (widget->window, &win_x, &win_y);
                if (root_x >= win_x && root_x < win_x + win_w &&
                    root_y >= win_y && root_y < win_y + win_h)
                    dock = GDL_DOCK (widget);
            }
        }
    }

    if (dock) {
        /* translate root coordinates into dock object coordinates
           (i.e. widget coordinates) */
        gdk_window_get_origin (GTK_WIDGET (dock)->window, &win_x, &win_y);
        x = root_x - win_x;
        y = root_y - win_y;
        may_dock = gdl_dock_object_dock_request (GDL_DOCK_OBJECT (dock),
                                                 x, y, &my_request);
    }
    else {
        GList *l;

        /* try to dock the item in all the docks in the ring in turn */
        for (l = master->toplevel_docks; l; l = l->next) {
            dock = GDL_DOCK (l->data);
            /* translate root coordinates into dock object coordinates
               (i.e. widget coordinates) */
            gdk_window_get_origin (GTK_WIDGET (dock)->window, &win_x, &win_y);
            x = root_x - win_x;
            y = root_y - win_y;
            may_dock = gdl_dock_object_dock_request (GDL_DOCK_OBJECT (dock),
                                                     x, y, &my_request);
            if (may_dock)
                break;
        }
    }

  
    if (!may_dock) {
        GtkRequisition req;
	/* Special case for GdlDockItems : they must respect the flags */
	if(GDL_IS_DOCK_ITEM(item)
	&& GDL_DOCK_ITEM(item)->behavior & GDL_DOCK_ITEM_BEH_NEVER_FLOATING)
	    return;

        dock = NULL;
        my_request.target = GDL_DOCK_OBJECT (
            gdl_dock_object_get_toplevel (request->applicant));
        my_request.position = GDL_DOCK_FLOATING;

        gdl_dock_item_preferred_size (GDL_DOCK_ITEM (request->applicant), &req);
        my_request.rect.width = req.width;
        my_request.rect.height = req.height;

        my_request.rect.x = root_x - GDL_DOCK_ITEM (request->applicant)->dragoff_x;
        my_request.rect.y = root_y - GDL_DOCK_ITEM (request->applicant)->dragoff_y;

        /* setup extra docking information */
        if (G_IS_VALUE (&my_request.extra))
            g_value_unset (&my_request.extra);

        g_value_init (&my_request.extra, GDK_TYPE_RECTANGLE);
        g_value_set_boxed (&my_request.extra, &my_request.rect);
    }
    /* if we want to enforce GDL_DOCK_ITEM_BEH_NEVER_FLOATING		*/
    /* the item must remain attached to the controller, otherwise	*/
    /* it could be inserted in another floating dock			*/
    /* so check for the flag at this moment				*/
    else if(GDL_IS_DOCK_ITEM(item)
	&& GDL_DOCK_ITEM(item)->behavior & GDL_DOCK_ITEM_BEH_NEVER_FLOATING
	&& dock != GDL_DOCK(master->controller))
	    return;

    if (!(my_request.rect.x == request->rect.x &&
          my_request.rect.y == request->rect.y &&
          my_request.rect.width == request->rect.width &&
          my_request.rect.height == request->rect.height &&
          dock == master->_priv->rect_owner)) {

        /* erase the previous rectangle */
        if (master->_priv->rect_drawn)
            gdl_dock_master_xor_rect (master);
    }

    /* set the new values */
    *request = my_request;
    master->_priv->rect_owner = dock;
    
    /* draw the previous rectangle */
    if (~master->_priv->rect_drawn)
        gdl_dock_master_xor_rect (master);
}
예제 #6
0
gboolean
_gdk_input_other_event (GdkEvent  *event,
                        MSG       *msg,
                        GdkWindow *window)
{
  GdkDisplay *display;
  GdkDeviceWintab *device = NULL;
  GdkDeviceGrabInfo *last_grab;
  GdkEventMask masktest;
  guint key_state;
  POINT pt;

  PACKET packet;
  gdouble root_x, root_y;
  gint num_axes;
  gint x, y;
  guint translated_buttons, button_diff, button_mask;
  /* Translation from tablet button state to GDK button state for
   * buttons 1-3 - swap button 2 and 3.
   */
  static guint button_map[8] = {0, 1, 4, 5, 2, 3, 6, 7};

  if (event->any.window != wintab_window)
    {
      g_warning ("_gdk_input_other_event: not wintab_window?");
      return FALSE;
    }

  window = gdk_window_at_pointer (&x, &y);
  if (window == NULL)
    window = _gdk_root;

  g_object_ref (window);
  display = gdk_window_get_display (window);

  GDK_NOTE (EVENTS_OR_INPUT,
	    g_print ("_gdk_input_other_event: window=%p %+d%+d\n",
               GDK_WINDOW_HWND (window), x, y));

  if (msg->message == WT_PACKET)
    {
      if (!(*p_WTPacket) ((HCTX) msg->lParam, msg->wParam, &packet))
        return FALSE;
    }

  switch (msg->message)
    {
    case WT_PACKET:
      /* Don't produce any button or motion events while a window is being
       * moved or resized, see bug #151090.
       */
      if (_modal_operation_in_progress)
        {
          GDK_NOTE (EVENTS_OR_INPUT, g_print ("... ignored when moving/sizing\n"));
          return FALSE;
        }

      if ((device = _gdk_device_manager_find_wintab_device ((HCTX) msg->lParam,
                                                            packet.pkCursor)) == NULL)
        return FALSE;

      if (gdk_device_get_mode (GDK_DEVICE (device)) == GDK_MODE_DISABLED)
        return FALSE;

      last_grab = _gdk_display_get_last_device_grab (_gdk_display, GDK_DEVICE (device));

      if (last_grab && last_grab->window)
        {
          g_object_unref (window);

          window = g_object_ref (last_grab->window);
        }

      if (window == _gdk_root)
        {
          GDK_NOTE (EVENTS_OR_INPUT, g_print ("... is root\n"));
          return FALSE;
        }

      num_axes = 0;
      if (device->pktdata & PK_X)
        device->last_axis_data[num_axes++] = packet.pkX;
      if (device->pktdata & PK_Y)
        device->last_axis_data[num_axes++] = packet.pkY;
      if (device->pktdata & PK_NORMAL_PRESSURE)
        device->last_axis_data[num_axes++] = packet.pkNormalPressure;
      if (device->pktdata & PK_ORIENTATION)
        {
          decode_tilt (device->last_axis_data + num_axes,
                       device->orientation_axes, &packet);
          num_axes += 2;
        }

      translated_buttons = button_map[packet.pkButtons & 0x07] | (packet.pkButtons & ~0x07);

      if (translated_buttons != device->button_state)
        {
          /* At least one button has changed state so produce a button event
           * If more than one button has changed state (unlikely),
           * just care about the first and act on the next the next time
           * we get a packet
           */
          button_diff = translated_buttons ^ device->button_state;

          /* Gdk buttons are numbered 1.. */
          event->button.button = 1;

          for (button_mask = 1; button_mask != 0x80000000;
               button_mask <<= 1, event->button.button++)
            {
              if (button_diff & button_mask)
                {
                  /* Found a button that has changed state */
                  break;
                }
            }

          if (!(translated_buttons & button_mask))
            {
              event->any.type = GDK_BUTTON_RELEASE;
              masktest = GDK_BUTTON_RELEASE_MASK;
            }
          else
            {
              event->any.type = GDK_BUTTON_PRESS;
              masktest = GDK_BUTTON_PRESS_MASK;
            }
          device->button_state ^= button_mask;
        }
      else
        {
          event->any.type = GDK_MOTION_NOTIFY;
          masktest = GDK_POINTER_MOTION_MASK;
          if (device->button_state & (1 << 0))
            masktest |= GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK;
          if (device->button_state & (1 << 1))
            masktest |= GDK_BUTTON_MOTION_MASK | GDK_BUTTON2_MOTION_MASK;
          if (device->button_state & (1 << 2))
            masktest |= GDK_BUTTON_MOTION_MASK | GDK_BUTTON3_MOTION_MASK;
        }

      /* Now we can check if the window wants the event, and
       * propagate if necessary.
       */
      while (gdk_window_get_device_events (window, GDK_DEVICE (device)) == 0)
        {
          GDK_NOTE (EVENTS_OR_INPUT, g_print ("... not selected\n"));

          if (window->parent == GDK_WINDOW (_gdk_root))
            return FALSE;

          /* It is not good to propagate the extended events up to the parent
           * if this window wants normal (not extended) motion/button events */
          if (window->event_mask & masktest)
            {
              GDK_NOTE (EVENTS_OR_INPUT,
                        g_print ("... wants ordinary event, ignoring this\n"));
              return FALSE;
            }

          pt.x = x;
          pt.y = y;
          ClientToScreen (GDK_WINDOW_HWND (window), &pt);
          g_object_unref (window);
          window = window->parent;
          g_object_ref (window);
          ScreenToClient (GDK_WINDOW_HWND (window), &pt);
          x = pt.x;
          y = pt.y;
          GDK_NOTE (EVENTS_OR_INPUT, g_print ("... propagating to %p %+d%+d\n",
                                              GDK_WINDOW_HWND (window), x, y));
        }

      if (gdk_window_get_device_events (window, GDK_DEVICE (device)) == 0)
        return FALSE;

      event->any.window = window;
      key_state = get_modifier_key_state ();
      if (event->any.type == GDK_BUTTON_PRESS ||
          event->any.type == GDK_BUTTON_RELEASE)
        {
          event->button.time = _gdk_win32_get_next_tick (msg->time);
          gdk_event_set_device (event, GDK_DEVICE (device));

          event->button.axes = g_new (gdouble, num_axes);
          _gdk_device_wintab_get_window_coords (window, &root_x, &root_y);

          _gdk_device_wintab_translate_axes (device,
                                             window,
                                             event->button.axes,
                                             &event->button.x,
                                             &event->button.y);

          event->button.x_root = event->button.x + root_x;
          event->button.y_root = event->button.y + root_y;

          event->button.state =
            key_state | ((device->button_state << 8)
                         & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK
                            | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK
                            | GDK_BUTTON5_MASK));

          GDK_NOTE (EVENTS_OR_INPUT,
                    g_print ("WINTAB button %s:%d %g,%g\n",
                             (event->button.type == GDK_BUTTON_PRESS ?
                              "press" : "release"),
                             event->button.button,
                             event->button.x, event->button.y));
        }
      else
        {
          event->motion.time = _gdk_win32_get_next_tick (msg->time);
          event->motion.is_hint = FALSE;
          gdk_event_set_device (event, GDK_DEVICE (device));

          event->motion.axes = g_new (gdouble, num_axes);
          _gdk_device_wintab_get_window_coords (window, &root_x, &root_y);

          _gdk_device_wintab_translate_axes (device,
                                             window,
                                             event->motion.axes,
                                             &event->motion.x,
                                             &event->motion.y);

          event->motion.x_root = event->motion.x + root_x;
          event->motion.y_root = event->motion.y + root_y;

          event->motion.state =
            key_state | ((device->button_state << 8)
                         & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK
                            | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK
                            | GDK_BUTTON5_MASK));

          GDK_NOTE (EVENTS_OR_INPUT,
                    g_print ("WINTAB motion: %g,%g\n",
                             event->motion.x, event->motion.y));
        }
      return TRUE;

    case WT_PROXIMITY:
      if (LOWORD (msg->lParam) == 0)
        {
          event->proximity.type = GDK_PROXIMITY_OUT;
          set_ignore_core (FALSE);
        }
      else
        {
          event->proximity.type = GDK_PROXIMITY_IN;
          set_ignore_core (TRUE);
        }
      event->proximity.time = _gdk_win32_get_next_tick (msg->time);
      gdk_event_set_device (event, GDK_DEVICE (device));

      GDK_NOTE (EVENTS_OR_INPUT,
                g_print ("WINTAB proximity %s\n",
                         (event->proximity.type == GDK_PROXIMITY_IN ?
                          "in" : "out")));
      return TRUE;
    }

  return FALSE;
}