static void
list_devices (GList *devices)
{
	GList *l;

	for (l = devices; l ; l = l->next) {
		GsdWacomDevice *device;
		GsdWacomDeviceType type;
		char *loc;

		device = l->data;

		g_signal_connect (G_OBJECT (device), "notify::last-stylus",
				  G_CALLBACK (last_stylus_changed), NULL);

		g_print ("Device '%s' (type: %s)\n",
			 gsd_wacom_device_get_name (device),
			 gsd_wacom_device_type_to_string (gsd_wacom_device_get_device_type (device)));
		g_print ("\tReversible: %s\n", BOOL_AS_STR (gsd_wacom_device_reversible (device)));
		g_print ("\tScreen Tablet: %s\n", BOOL_AS_STR (gsd_wacom_device_is_screen_tablet (device)));
		g_print ("\tUnknown (fallback) device: %s\n", BOOL_AS_STR(gsd_wacom_device_is_fallback (device)));

		loc = get_loc (gsd_wacom_device_get_settings (device));
		g_print ("\tGeneric settings: %s\n", loc);
		g_free (loc);

		type = gsd_wacom_device_get_device_type (device);
		if (type == WACOM_TYPE_STYLUS ||
		    type == WACOM_TYPE_ERASER) {
			GList *styli, *j;
			GsdWacomStylus *current_stylus;

			g_object_get (device, "last-stylus", &current_stylus, NULL);

			styli = gsd_wacom_device_list_styli (device);
			for (j = styli; j; j = j->next) {
				GsdWacomStylus *stylus;

				stylus = j->data;
				print_stylus (stylus, current_stylus == stylus);
			}
			g_list_free (styli);
		}

		print_buttons (device);

		if (monitor_styli == FALSE)
			g_object_unref (device);
	}
	g_list_free (devices);
}
Пример #2
0
static void
update_current_page (CcWacomPanel *self)
{
	GHashTable *ht;
	GList *devices, *tablets, *l;
	gboolean changed;
	CcWacomPanelPrivate *priv;

	priv = self->priv;
	changed = FALSE;

	ht = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
	devices = g_hash_table_get_values (priv->devices);
	for (l = devices; l; l = l->next) {
		Tablet *tablet;
		GsdWacomDevice *device;

		device = l->data;
		tablet = g_hash_table_lookup (ht, gsd_wacom_device_get_name (device));
		if (tablet == NULL) {
			tablet = g_new0 (Tablet, 1);
			tablet->name = gsd_wacom_device_get_name (device);
			g_hash_table_insert (ht, (gpointer) tablet->name, tablet);
		}

		switch (gsd_wacom_device_get_device_type (device)) {
		case WACOM_TYPE_STYLUS:
			tablet->stylus = device;
			break;
		case WACOM_TYPE_ERASER:
			tablet->eraser = device;
			break;
		case WACOM_TYPE_PAD:
			tablet->pad = device;
			break;
		default:
			/* Nothing */
			;
		}
	}
	g_list_free (devices);

	/* We now have a list of Tablet structs,
	 * see which ones are full tablets */
	tablets = g_hash_table_get_values (ht);
	for (l = tablets; l; l = l->next) {
		Tablet *tablet;
		GtkWidget *page;

		tablet = l->data;
		if (tablet->stylus == NULL ||
		    tablet->eraser == NULL) {
			page = g_hash_table_lookup (priv->pages, tablet->name);
			if (page != NULL) {
				remove_page (GTK_NOTEBOOK (priv->notebook), page);
				g_hash_table_remove (priv->pages, tablet->name);

				changed = TRUE;
			}
			continue;
		}
		/* this code is called once the stylus + eraser were set up, but the pad does not exist yet */
		page = g_hash_table_lookup (priv->pages, tablet->name);
		if (page == NULL) {
			page = cc_wacom_page_new (self, tablet->stylus, tablet->eraser, tablet->pad);
			cc_wacom_page_set_navigation (CC_WACOM_PAGE (page), GTK_NOTEBOOK (priv->notebook), TRUE);
			gtk_widget_show (page);
			gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), page, NULL);
			g_hash_table_insert (priv->pages, g_strdup (tablet->name), page);

			changed = TRUE;
		} else {
			cc_wacom_page_update_tools (CC_WACOM_PAGE (page), tablet->stylus, tablet->eraser, tablet->pad);
		}
	}
	g_list_free (tablets);

	g_hash_table_destroy (ht);

	if (changed == TRUE) {
		int num_pages;

		num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
		if (num_pages > 1)
			gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), WACOM_PAGE);
	}
}
Пример #3
0
int main(int argc, char** argv)
{
    GtkWidget *widget;
    GError *error = NULL;
    GOptionContext *context;
    GsdWacomDevice *device;
    gchar *message;
    gchar *tablet = NULL;
    const GOptionEntry entries[] = {
        { "tablet", 't', 0, G_OPTION_ARG_STRING, &tablet, "Name of the tablet to show", "<string>"},
        { "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug, "Debug output", NULL },
        { NULL }
    };

    gtk_init (&argc, &argv);

    context = g_option_context_new ("- test functions");
    g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
    g_option_context_add_group (context, gtk_get_option_group (TRUE));
    g_option_context_set_help_enabled (context, TRUE);
    if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
        g_print ("%s\n", error->message);
        return 1;
    }
    g_option_context_free (context);

    if (option_debug)
        g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);

    if (tablet)
        device = create_fake_device (tablet);
    else
        device = search_pad_device ();

    if (device == NULL) {
        g_print ("No pad device found, consider using --tablet\n");
        return 1;
    }

    if (gsd_wacom_device_get_layout_path (device) == NULL) {
        g_print ("This device has not layout available in libwacom\n");
        return 1;
    }

    message = g_strdup_printf ("<big><b>%s</b></big>\n<i>(Press a key to exit)</i>",
                               gsd_wacom_device_get_name (device));
    widget = gsd_wacom_osd_window_new (device, message);
    g_free (message);

    g_signal_connect (widget, "key-release-event",
                      G_CALLBACK(on_key_release_event), NULL);
    g_signal_connect (widget, "delete-event",
                      G_CALLBACK (gtk_main_quit), NULL);
    g_signal_connect (widget, "unmap",
                      G_CALLBACK (gtk_main_quit), NULL);

    gtk_widget_show (widget);
    gtk_main ();

    return 0;
}