void on_monitors_changed ( GdkScreen *screen, gpointer user_data) { GromitData *data = (GromitData *) user_data; if(data->debug) g_printerr("DEBUG: screen size changed!\n"); // get new sizes data->width = gdk_screen_get_width (data->screen); data->height = gdk_screen_get_height (data->screen); // change size gtk_widget_set_size_request(GTK_WIDGET(data->win), data->width, data->height); // try to set transparent for input cairo_region_t* r = cairo_region_create(); gtk_widget_input_shape_combine_region(data->win, r); cairo_region_destroy(r); /* recreate the shape surface */ cairo_surface_t *new_shape = cairo_image_surface_create(CAIRO_FORMAT_ARGB32 ,data->width, data->height); cairo_t *cr = cairo_create (new_shape); cairo_set_source_surface (cr, data->backbuffer, 0, 0); cairo_paint (cr); cairo_destroy (cr); cairo_surface_destroy(data->backbuffer); data->backbuffer = new_shape; /* these depend on the shape surface */ GHashTableIter it; gpointer value; g_hash_table_iter_init (&it, data->tool_config); while (g_hash_table_iter_next (&it, NULL, &value)) paint_context_free(value); g_hash_table_remove_all(data->tool_config); parse_config(data); // also calls paint_context_new() :-( data->default_pen = paint_context_new (data, GROMIT_PEN, data->red, 7, 0, 1); data->default_eraser = paint_context_new (data, GROMIT_ERASER, data->red, 75, 0, 1); if(!data->composited) // set shape { cairo_region_t* r = gdk_cairo_region_create_from_surface(data->backbuffer); gtk_widget_shape_combine_region(data->win, r); cairo_region_destroy(r); } setup_input_devices(data); gtk_widget_show_all (data->win); }
void on_device_added (GdkDeviceManager *device_manager, GdkDevice *device, gpointer user_data) { GromitData *data = (GromitData *) user_data; GdkInputSource hardware_type = gdk_device_get_source(device); if( hardware_type == GDK_SOURCE_KEYBOARD || gdk_device_get_n_axes(device) < 2) return; if(data->debug) g_printerr("DEBUG: device '%s' added\n", gdk_device_get_name(device)); setup_input_devices(data); }
/* Remote control */ void on_mainapp_selection_get (GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint time, gpointer user_data) { GromitData *data = (GromitData *) user_data; gchar *uri = "OK"; GdkAtom action = gtk_selection_data_get_target(selection_data); if(action == GA_TOGGLE) { /* ask back client for device id */ gtk_selection_convert (data->win, GA_DATA, GA_TOGGLEDATA, time); gtk_main(); /* Wait for the response */ } else if (action == GA_VISIBILITY) toggle_visibility (data); else if (action == GA_CLEAR) clear_screen (data); else if (action == GA_RELOAD) setup_input_devices(data); else if (action == GA_QUIT) gtk_main_quit (); else if (action == GA_UNDO) undo_drawing (data); else if (action == GA_REDO) redo_drawing (data); else uri = "NOK"; gtk_selection_data_set (selection_data, gtk_selection_data_get_target(selection_data), 8, (guchar*)uri, strlen (uri)); }
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)); } }