Ejemplo n.º 1
0
static gboolean
gstyle_eyedropper_pointer_released_cb (GstyleEyedropper *self,
                                       GdkEventButton   *event,
                                       GtkWindow        *window)
{
  GdkRGBA rgba;

  g_assert (GSTYLE_IS_EYEDROPPER (self));
  g_assert (event != NULL);
  g_assert (GTK_IS_WINDOW (window));
  g_assert (self->screen == gdk_event_get_screen ((GdkEvent *) event));

  get_rgba_at_cursor (self,
                      self->screen,
                      gdk_event_get_device ((GdkEvent *) event),
                      event->x_root, event->y_root, &rgba);

  gstyle_color_set_rgba (self->color, &rgba);
  g_signal_emit (self, signals [COLOR_PICKED], 0, &rgba);

  release_grab (self);
  self->button_pressed = FALSE;

  return GDK_EVENT_STOP;
}
Ejemplo n.º 2
0
static void
gstyle_eyedropper_finalize (GObject *object)
{
  GstyleEyedropper *self = GSTYLE_EYEDROPPER (object);

  release_grab (self);
  g_clear_object (&self->color);

  G_OBJECT_CLASS (gstyle_eyedropper_parent_class)->finalize (object);
}
Ejemplo n.º 3
0
static gboolean
gstyle_eyedropper_grab_broken_cb (GstyleEyedropper *self,
                                  GdkEventKey      *event,
                                  GtkWidget        *window)
{
  g_assert (GSTYLE_IS_EYEDROPPER (self));
  g_assert (event != NULL);
  g_assert (GTK_IS_WINDOW (window));

  release_grab (self);

  return GDK_EVENT_STOP;
}
Ejemplo n.º 4
0
void toggle_grab (GromitData *data,
                  GdkDevice* dev)
{
    if(dev == NULL) /* toggle all */
    {
        if (data->all_grabbed)
            release_grab (data, NULL);
        else
            acquire_grab (data, NULL);
        return;
    }

    GromitDeviceData *devdata =
        g_hash_table_lookup(data->devdatatable, dev);
    if(devdata)
    {
        if(devdata->is_grabbed)
            release_grab (data, devdata->device);
        else
            acquire_grab (data, devdata->device);
    }
    else
        g_printerr("ERROR: No such device '%s' in internal table.\n", gdk_device_get_name(dev));
}
Ejemplo n.º 5
0
static gboolean
gstyle_eyedropper_key_pressed_cb (GstyleEyedropper *self,
                                  GdkEventKey      *event,
                                  GtkWindow        *window)
{
  GdkSeat *seat;
  GdkDevice *pointer;
  GdkDevice *keyboard;
  gint x, y;
  gint dx = 0;
  gint dy = 0;
  gint state;

  g_assert (GSTYLE_IS_EYEDROPPER (self));
  g_assert (event != NULL);
  g_assert (GTK_IS_WINDOW (window));

  state = (event->state & gtk_accelerator_get_default_mod_mask () & GDK_MOD1_MASK);
  switch (event->keyval)
    {
    case GDK_KEY_Escape:
      release_grab (self);
      return GDK_EVENT_STOP;
      break;

    case GDK_KEY_Up:
    case GDK_KEY_KP_Up:
      dy = (state == GDK_MOD1_MASK) ? -CURSOR_ALT_STEP : -1;
      break;

    case GDK_KEY_Down:
    case GDK_KEY_KP_Down:
      dy = (state == GDK_MOD1_MASK) ? CURSOR_ALT_STEP : 1;
      break;

    case GDK_KEY_Left:
    case GDK_KEY_KP_Left:
      dx = (state == GDK_MOD1_MASK) ? -CURSOR_ALT_STEP : -1;
      break;

    case GDK_KEY_Right:
    case GDK_KEY_KP_Right:
      dx = (state == GDK_MOD1_MASK) ? CURSOR_ALT_STEP : 1;
      break;

    case GDK_KEY_Page_Up:
    case GDK_KEY_KP_Page_Up:
      increase_zoom_factor (self);
      break;

    case GDK_KEY_Page_Down:
    case GDK_KEY_KP_Page_Down:
      decrease_zoom_factor (self);
      break;

    default:
      return GDK_EVENT_PROPAGATE;
    }

  keyboard = gdk_event_get_device ((GdkEvent *)event);
  seat = gdk_device_get_seat (keyboard);
  pointer = gdk_seat_get_pointer (seat);
  gdk_device_get_position (pointer, NULL, &x, &y);
  gdk_device_warp (pointer, self->screen, x + dx, y + dy);

  return GDK_EVENT_STOP;
}
Ejemplo n.º 6
0
void setup_input_devices (GromitData *data)
{
    /* ungrab all */
    release_grab (data, NULL);

    /* and clear our own device data list */
    GHashTableIter it;
    gpointer value;
    g_hash_table_iter_init (&it, data->devdatatable);
    while (g_hash_table_iter_next (&it, NULL, &value))
        g_free(value);
    g_hash_table_remove_all(data->devdatatable);


    /* get devices */
    GdkDeviceManager *device_manager = gdk_display_get_device_manager(data->display);
    GList *devices, *d;
    int i = 0;

    devices = g_list_concat(gdk_device_manager_list_devices
                            (device_manager, GDK_DEVICE_TYPE_MASTER),
                            gdk_device_manager_list_devices
                            (device_manager, GDK_DEVICE_TYPE_SLAVE));
    for(d = devices; d; d = d->next)
    {
        GdkDevice *device = (GdkDevice *) d->data;

        /* only enable devices with 2 ore more axes */
        if (gdk_device_get_source(device) != GDK_SOURCE_KEYBOARD && gdk_device_get_n_axes(device) >= 2)
        {
            gdk_device_set_mode (device, GDK_MODE_SCREEN);

            GromitDeviceData *devdata;

            devdata  = g_malloc0(sizeof (GromitDeviceData));
            devdata->device = device;
            devdata->index = i;

            /* get attached keyboard and grab the hotkey */
            if (!data->hot_keycode)
            {
                g_printerr("ERROR: Grabbing hotkey from attached keyboard "
                           "of '%s' failed, no hotkey defined.\n",
                           gdk_device_get_name(device));
                g_free(devdata);
                continue;
            }

            /* if this is a slave device, we need the master */
            GdkDevice *kdevice=device;
            if(gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_SLAVE)
                kdevice=gdk_device_get_associated_device (device);

            gint dev_id = -1;
            g_object_get(kdevice, "device-id", &dev_id, NULL);

            gint kbd_dev_id = -1;
            XIDeviceInfo* devinfo;
            int devicecount = 0;

            devinfo = XIQueryDevice(GDK_DISPLAY_XDISPLAY(data->display),
                                    dev_id,
                                    &devicecount);
            if(devicecount)
                kbd_dev_id = devinfo->attachment;
            XIFreeDeviceInfo(devinfo);

            if(kbd_dev_id != -1)
            {
                if(data->debug)
                    g_printerr("DEBUG: Grabbing hotkey from keyboard '%d' .\n", kbd_dev_id);

                XIEventMask mask;
                unsigned char bits[4] = {0,0,0,0};
                mask.mask = bits;
                mask.mask_len = sizeof(bits);

                XISetMask(bits, XI_KeyPress);
                XISetMask(bits, XI_KeyRelease);

                XIGrabModifiers modifiers[] = {{XIAnyModifier, 0}};
                int nmods = 1;

                gdk_error_trap_push ();

                XIGrabKeycode( GDK_DISPLAY_XDISPLAY(data->display),
                               kbd_dev_id,
                               data->hot_keycode,
                               GDK_WINDOW_XID(data->root),
                               GrabModeAsync,
                               GrabModeAsync,
                               True,
                               &mask,
                               nmods,
                               modifiers);

                XSync(GDK_DISPLAY_XDISPLAY(data->display), False);
                if(gdk_error_trap_pop())
                {
                    g_printerr("ERROR: Grabbing hotkey from keyboard device %d failed.\n",
                               kbd_dev_id);
                    g_free(devdata);
                    continue;
                }
            }

            g_hash_table_insert(data->devdatatable, device, devdata);
            g_printerr ("Enabled Device %d: \"%s\", (Type: %d)\n",
                        i++, gdk_device_get_name(device), gdk_device_get_source(device));
        }
    }

    g_printerr ("Now %d enabled devices.\n", g_hash_table_size(data->devdatatable));
}