added GdkDisplay member since there is no way fo figure the display a

2005-11-27  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpdeviceinfo.[ch]: added GdkDisplay member since
	there is no way fo figure the display a GdkDevice exists on.
	Minor cleanups.

	* app/widgets/gimpdevices.[ch]: connect to the GdkDeviceManager
	and add input devices when displays are opened. Added API to get
	the GimpContainer of devices.

	* app/widgets/gimpdevicestatus.[ch]: don't just show the devices
	of the default display. Instead get the device container from the
	new API above and update the GUI when devices are added/removed.
	Cleaned up the whole file quite a bit.
This commit is contained in:
Michael Natterer 2005-11-27 17:20:40 +00:00 committed by Michael Natterer
parent ae78c0ebc7
commit 84fed8962d
7 changed files with 430 additions and 249 deletions

View File

@ -1,3 +1,18 @@
2005-11-27 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpdeviceinfo.[ch]: added GdkDisplay member since
there is no way fo figure the display a GdkDevice exists on.
Minor cleanups.
* app/widgets/gimpdevices.[ch]: connect to the GdkDeviceManager
and add input devices when displays are opened. Added API to get
the GimpContainer of devices.
* app/widgets/gimpdevicestatus.[ch]: don't just show the devices
of the default display. Instead get the device container from the
new API above and update the GUI when devices are added/removed.
Cleaned up the whole file quite a bit.
2005-11-27 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpdeviceinfo.c (gimp_device_info_get_property):

View File

@ -155,6 +155,7 @@ static void
gimp_device_info_init (GimpDeviceInfo *device_info)
{
device_info->device = NULL;
device_info->display = NULL;
device_info->mode = GDK_MODE_DISABLED;
device_info->num_axes = 0;
device_info->axes = NULL;
@ -237,8 +238,8 @@ gimp_device_info_set_property (GObject *object,
switch (property_id)
{
case PROP_MODE:
if (device_info->device)
gdk_device_set_mode (device_info->device, g_value_get_enum (value));
if (device)
gdk_device_set_mode (device, g_value_get_enum (value));
else
device_info->mode = g_value_get_enum (value);
break;
@ -423,29 +424,28 @@ GimpDeviceInfo *
gimp_device_info_new (Gimp *gimp,
const gchar *name)
{
GimpDeviceInfo *device_info;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (name != NULL, NULL);
device_info = g_object_new (GIMP_TYPE_DEVICE_INFO,
"name", name,
"gimp", gimp,
NULL);
return device_info;
return g_object_new (GIMP_TYPE_DEVICE_INFO,
"name", name,
"gimp", gimp,
NULL);
}
GimpDeviceInfo *
gimp_device_info_set_from_device (GimpDeviceInfo *device_info,
GdkDevice *device)
GdkDevice *device,
GdkDisplay *display)
{
g_return_val_if_fail (GIMP_IS_DEVICE_INFO (device_info), NULL);
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
g_object_set_data (G_OBJECT (device), GIMP_DEVICE_INFO_DATA_KEY, device_info);
device_info->device = device;
device_info->display = display;
device_info->mode = device->mode;
@ -481,7 +481,7 @@ gimp_device_info_changed_by_device (GdkDevice *device)
g_return_if_fail (GDK_IS_DEVICE (device));
device_info = g_object_get_data (G_OBJECT (device), GIMP_DEVICE_INFO_DATA_KEY);
device_info = gimp_device_info_get_by_device (device);
if (device_info)
gimp_device_info_changed (device_info);

View File

@ -51,6 +51,7 @@ struct _GimpDeviceInfo
GimpContext parent_instance;
GdkDevice *device;
GdkDisplay *display;
/* either "device" or the options below are set */
@ -75,7 +76,8 @@ GimpDeviceInfo * gimp_device_info_new (Gimp *gimp,
const gchar *name);
GimpDeviceInfo * gimp_device_info_set_from_device (GimpDeviceInfo *device_info,
GdkDevice *device);
GdkDevice *device,
GdkDisplay *display);
void gimp_device_info_changed (GimpDeviceInfo *device_info);
GimpDeviceInfo * gimp_device_info_get_by_device (GdkDevice *device);

View File

@ -57,6 +57,7 @@ typedef struct _GimpDeviceManager GimpDeviceManager;
struct _GimpDeviceManager
{
Gimp *gimp;
GimpContainer *device_info_list;
GdkDevice *current_device;
GimpDeviceChangeNotify change_notify;
@ -69,6 +70,13 @@ struct _GimpDeviceManager
static GimpDeviceManager * gimp_device_manager_get (Gimp *gimp);
static void gimp_device_manager_free (GimpDeviceManager *manager);
static void gimp_devices_display_opened (GdkDisplayManager *disp_manager,
GdkDisplay *display,
GimpDeviceManager *manager);
static void gimp_devices_display_closed (GdkDisplay *display,
gboolean is_error,
GimpDeviceManager *manager);
/* public functions */
@ -76,9 +84,11 @@ void
gimp_devices_init (Gimp *gimp,
GimpDeviceChangeNotify change_notify)
{
GdkDisplayManager *disp_manager = gdk_display_manager_get ();
GimpDeviceManager *manager;
GList *list;
GdkDisplay *display;
GSList *displays;
GSList *list;
GdkDisplay *gdk_display;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (gimp_device_manager_get (gimp) == NULL);
@ -89,31 +99,44 @@ gimp_devices_init (Gimp *gimp,
GIMP_DEVICE_MANAGER_DATA_KEY, manager,
(GDestroyNotify) gimp_device_manager_free);
display = gdk_display_get_default ();
gdk_display = gdk_display_get_default ();
manager->gimp = gimp;
manager->device_info_list = gimp_list_new (GIMP_TYPE_DEVICE_INFO, FALSE);
manager->current_device = gdk_display_get_core_pointer (display);
manager->current_device = gdk_display_get_core_pointer (gdk_display);
manager->change_notify = change_notify;
/* create device info structures for present devices */
for (list = gdk_display_list_devices (display); list; list = list->next)
displays = gdk_display_manager_list_displays (disp_manager);
/* present displays in the order in which they were opened */
displays = g_slist_reverse (displays);
for (list = displays; list; list = g_slist_next (list))
{
GdkDevice *device = list->data;
GimpDeviceInfo *device_info;
device_info = gimp_device_info_new (gimp, device->name);
gimp_container_add (manager->device_info_list, GIMP_OBJECT (device_info));
g_object_unref (device_info);
gimp_device_info_set_from_device (device_info, device);
gimp_devices_display_opened (disp_manager, list->data, manager);
}
g_slist_free (displays);
g_signal_connect (disp_manager, "display-opened",
G_CALLBACK (gimp_devices_display_opened),
manager);
}
void
gimp_devices_exit (Gimp *gimp)
{
GimpDeviceManager *manager;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (gimp_device_manager_get (gimp) != NULL);
manager = gimp_device_manager_get (gimp);
g_return_if_fail (manager != NULL);
g_signal_handlers_disconnect_by_func (gdk_display_manager_get (),
gimp_devices_display_opened,
manager);
g_object_set_data (G_OBJECT (gimp), GIMP_DEVICE_MANAGER_DATA_KEY, NULL);
}
@ -246,6 +269,20 @@ gimp_devices_clear (Gimp *gimp,
return success;
}
GimpContainer *
gimp_devices_get_list (Gimp *gimp)
{
GimpDeviceManager *manager;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
manager = gimp_device_manager_get (gimp);
g_return_val_if_fail (manager != NULL, NULL);
return manager->device_info_list;
}
GdkDevice *
gimp_devices_get_current (Gimp *gimp)
{
@ -374,3 +411,36 @@ gimp_device_manager_free (GimpDeviceManager *manager)
g_free (manager);
}
static void
gimp_devices_display_opened (GdkDisplayManager *disp_manager,
GdkDisplay *gdk_display,
GimpDeviceManager *manager)
{
GList *list;
/* create device info structures for present devices */
for (list = gdk_display_list_devices (gdk_display); list; list = list->next)
{
GdkDevice *device = list->data;
GimpDeviceInfo *device_info;
device_info = gimp_device_info_new (manager->gimp, device->name);
gimp_device_info_set_from_device (device_info, device, gdk_display);
gimp_container_add (manager->device_info_list, GIMP_OBJECT (device_info));
g_object_unref (device_info);
}
g_signal_connect (gdk_display, "closed",
G_CALLBACK (gimp_devices_display_closed),
manager);
}
static void
gimp_devices_display_closed (GdkDisplay *gdk_display,
gboolean is_error,
GimpDeviceManager *manager)
{
}

View File

@ -23,23 +23,24 @@
typedef void (* GimpDeviceChangeNotify) (Gimp *gimp);
void gimp_devices_init (Gimp *gimp,
GimpDeviceChangeNotify change_notify);
void gimp_devices_exit (Gimp *gimp);
void gimp_devices_init (Gimp *gimp,
GimpDeviceChangeNotify callback);
void gimp_devices_exit (Gimp *gimp);
void gimp_devices_restore (Gimp *gimp);
void gimp_devices_save (Gimp *gimp,
gboolean always_save);
void gimp_devices_restore (Gimp *gimp);
void gimp_devices_save (Gimp *gimp,
gboolean always_save);
gboolean gimp_devices_clear (Gimp *gimp,
GError **error);
gboolean gimp_devices_clear (Gimp *gimp,
GError **error);
GdkDevice * gimp_devices_get_current (Gimp *gimp);
GimpContainer * gimp_devices_get_list (Gimp *gimp);
GdkDevice * gimp_devices_get_current (Gimp *gimp);
gboolean gimp_devices_check_change (Gimp *gimp,
GdkEvent *event);
void gimp_devices_select_device (Gimp *gimp,
GdkDevice *device);
gboolean gimp_devices_check_change (Gimp *gimp,
GdkEvent *event);
void gimp_devices_select_device (Gimp *gimp,
GdkDevice *device);
#endif /* __GIMP_DEVICES_H__ */

View File

@ -30,9 +30,9 @@
#include "core/gimp.h"
#include "core/gimpbrush.h"
#include "core/gimpcontainer.h"
#include "core/gimpdatafactory.h"
#include "core/gimpgradient.h"
#include "core/gimplist.h"
#include "core/gimppattern.h"
#include "core/gimptoolinfo.h"
@ -50,27 +50,49 @@
#define CELL_SIZE 20 /* The size of the view cells */
enum
{
PROP_0,
PROP_GIMP
};
struct _GimpDeviceStatusEntry
{
GdkDevice *device;
GimpDeviceInfo *device_info;
GtkWidget *separator;
GtkWidget *label;
GtkWidget *arrow;
GtkWidget *tool;
GtkWidget *foreground;
GtkWidget *background;
GtkWidget *brush;
GtkWidget *pattern;
GtkWidget *gradient;
GtkWidget *table;
GtkWidget *label;
GtkWidget *arrow;
GtkWidget *tool;
GtkWidget *foreground;
GtkWidget *background;
GtkWidget *brush;
GtkWidget *pattern;
GtkWidget *gradient;
};
static void gimp_device_status_class_init (GimpDeviceStatusClass *klass);
static void gimp_device_status_init (GimpDeviceStatus *editor);
static GObject *gimp_device_status_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_device_status_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void gimp_device_status_destroy (GtkObject *object);
static void gimp_device_status_device_add (GimpContainer *devices,
GimpDeviceInfo *device_info,
GimpDeviceStatus *status);
static void gimp_device_status_device_remove (GimpContainer *devices,
GimpDeviceInfo *device_info,
GimpDeviceStatus *status);
static void gimp_device_status_update_entry (GimpDeviceInfo *device_info,
GimpDeviceStatusEntry *entry);
static void gimp_device_status_save_clicked (GtkWidget *button,
@ -114,167 +136,33 @@ gimp_device_status_get_type (void)
static void
gimp_device_status_class_init (GimpDeviceStatusClass *klass)
{
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->destroy = gimp_device_status_destroy;
object_class->constructor = gimp_device_status_constructor;
object_class->set_property = gimp_device_status_set_property;
gtk_object_class->destroy = gimp_device_status_destroy;
g_object_class_install_property (object_class, PROP_GIMP,
g_param_spec_object ("gimp", NULL, NULL,
GIMP_TYPE_GIMP,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_device_status_init (GimpDeviceStatus *status)
{
GdkDisplay *display;
GList *list;
gint i;
display = gtk_widget_get_display (GTK_WIDGET (status));
status->gimp = NULL;
status->current_device = NULL;
status->num_devices = g_list_length (gdk_display_list_devices (display));
status->entries = g_new0 (GimpDeviceStatusEntry,
status->num_devices);
status->table = gtk_table_new (status->num_devices * 3, 7, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (status->table), 6);
gtk_table_set_col_spacings (GTK_TABLE (status->table), 6);
gtk_container_add (GTK_CONTAINER (status), status->table);
gtk_widget_show (status->table);
for (list = gdk_display_list_devices (display), i = 0;
list;
list = list->next, i++)
{
GimpDeviceInfo *device_info;
GimpContext *context;
GimpDeviceStatusEntry *entry = &status->entries[i];
gint row = i * 3;
gchar *markup;
GClosure *closure;
entry->device = GDK_DEVICE (list->data);
device_info = gimp_device_info_get_by_device (entry->device);
context = GIMP_CONTEXT (device_info);
closure = g_cclosure_new (G_CALLBACK (gimp_device_status_update_entry),
entry, NULL);
g_object_watch_closure (G_OBJECT (status), closure);
g_signal_connect_closure (device_info, "changed", closure, FALSE);
/* the separator */
entry->separator = gtk_hbox_new (FALSE, 0);
gtk_table_attach (GTK_TABLE (status->table), entry->separator,
0, 7, row, row + 1,
GTK_FILL, GTK_FILL, 0, 2);
row++;
/* the device name */
entry->label = gtk_label_new (NULL);
markup = g_strdup_printf ("<b>%s</b>", GIMP_OBJECT (device_info)->name);
gtk_label_set_markup (GTK_LABEL (entry->label), markup);
g_free (markup);
gtk_widget_set_size_request (entry->label, -1, CELL_SIZE);
gtk_misc_set_alignment (GTK_MISC (entry->label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (status->table), entry->label,
1, 7, row, row + 1,
GTK_FILL, GTK_FILL, 0, 2);
entry->arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
gtk_widget_set_size_request (entry->arrow, CELL_SIZE, CELL_SIZE);
gtk_table_attach (GTK_TABLE (status->table), entry->arrow,
0, 1, row, row + 1,
GTK_FILL, GTK_FILL, 0, 0);
row++;
/* the tool */
entry->tool = gimp_prop_preview_new (G_OBJECT (context),
"tool", CELL_SIZE);
GIMP_VIEW (entry->tool)->clickable = TRUE;
gtk_table_attach (GTK_TABLE (status->table), entry->tool,
1, 2, row, row + 1,
0, 0, 0, 0);
g_signal_connect (entry->tool, "clicked",
G_CALLBACK (gimp_device_status_preview_clicked),
"gimp-tool-list|gimp-tool-grid");
/* the foreground color */
entry->foreground = gimp_prop_color_area_new (G_OBJECT (context),
"foreground",
CELL_SIZE, CELL_SIZE,
GIMP_COLOR_AREA_FLAT);
gtk_widget_add_events (entry->foreground,
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
gtk_table_attach (GTK_TABLE (status->table), entry->foreground,
2, 3, row, row + 1,
0, 0, 0, 0);
/* the background color */
entry->background = gimp_prop_color_area_new (G_OBJECT (context),
"background",
CELL_SIZE, CELL_SIZE,
GIMP_COLOR_AREA_FLAT);
gtk_widget_add_events (entry->background,
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
gtk_table_attach (GTK_TABLE (status->table), entry->background,
3, 4, row, row + 1,
0, 0, 0, 0);
/* the brush */
entry->brush = gimp_prop_preview_new (G_OBJECT (context),
"brush", CELL_SIZE);
GIMP_VIEW (entry->brush)->clickable = TRUE;
GIMP_VIEW (entry->brush)->show_popup = TRUE;
gtk_table_attach (GTK_TABLE (status->table), entry->brush,
4, 5, row, row + 1,
0, 0, 0, 0);
g_signal_connect (entry->brush, "clicked",
G_CALLBACK (gimp_device_status_preview_clicked),
"gimp-brush-grid|gimp-brush-list");
/* the pattern */
entry->pattern = gimp_prop_preview_new (G_OBJECT (context),
"pattern", CELL_SIZE);
GIMP_VIEW (entry->pattern)->clickable = TRUE;
GIMP_VIEW (entry->pattern)->show_popup = TRUE;
gtk_table_attach (GTK_TABLE (status->table), entry->pattern,
5, 6, row, row + 1,
0, 0, 0, 0);
g_signal_connect (entry->pattern, "clicked",
G_CALLBACK (gimp_device_status_preview_clicked),
"gimp-pattern-grid|gimp-pattern-list");
/* the gradient */
entry->gradient = gimp_prop_preview_new (G_OBJECT (context),
"gradient", 2 * CELL_SIZE);
GIMP_VIEW (entry->gradient)->clickable = TRUE;
GIMP_VIEW (entry->gradient)->show_popup = TRUE;
gtk_table_attach (GTK_TABLE (status->table), entry->gradient,
6, 7, row, row + 1,
0, 0, 0, 0);
g_signal_connect (entry->gradient, "clicked",
G_CALLBACK (gimp_device_status_preview_clicked),
"gimp-gradient-list|gimp-gradient-grid");
gimp_device_status_update_entry (device_info, entry);
}
status->vbox = gtk_vbox_new (FALSE, 12);
gtk_container_set_border_width (GTK_CONTAINER (status->vbox), 6);
gtk_container_add (GTK_CONTAINER (status), status->vbox);
gtk_widget_show (status->vbox);
status->save_button =
gimp_editor_add_button (GIMP_EDITOR (status), GTK_STOCK_SAVE,
@ -284,62 +172,282 @@ gimp_device_status_init (GimpDeviceStatus *status)
status);
}
static GObject *
gimp_device_status_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpDeviceStatus *status;
GimpContainer *devices;
GList *list;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
status = GIMP_DEVICE_STATUS (object);
g_assert (GIMP_IS_GIMP (status->gimp));
devices = gimp_devices_get_list (status->gimp);
for (list = GIMP_LIST (devices)->list; list; list = list->next)
gimp_device_status_device_add (devices, list->data, status);
g_signal_connect_object (devices, "add",
G_CALLBACK (gimp_device_status_device_add),
status, 0);
g_signal_connect_object (devices, "remove",
G_CALLBACK (gimp_device_status_device_remove),
status, 0);
gimp_device_status_update (status);
return object;
}
static void
gimp_device_status_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpDeviceStatus *status = GIMP_DEVICE_STATUS (object);
switch (property_id)
{
case PROP_GIMP:
status->gimp = GIMP (g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_device_status_destroy (GtkObject *object)
{
GimpDeviceStatus *status = GIMP_DEVICE_STATUS (object);
if (status->entries)
if (status->devices)
{
gint i;
GList *list;
for (i = 0; i < status->num_devices; i++)
for (list = status->devices; list; list = list->next)
{
GimpDeviceStatusEntry *entry = &status->entries[i];
GimpDeviceStatusEntry *entry = list->data;
g_signal_handlers_disconnect_by_func (entry->device,
g_signal_handlers_disconnect_by_func (entry->device_info,
gimp_device_status_update_entry,
entry);
g_free (entry);
}
g_free (status->entries);
status->entries = NULL;
status->num_devices = 0;
g_list_free (status->devices);
status->devices = NULL;
}
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_device_status_device_add (GimpContainer *devices,
GimpDeviceInfo *device_info,
GimpDeviceStatus *status)
{
GimpContext *context = GIMP_CONTEXT (device_info);
GimpDeviceStatusEntry *entry;
GtkWidget *hbox;
GClosure *closure;
gchar *name;
/* only list present devices */
if (! device_info->device)
return;
entry = g_new0 (GimpDeviceStatusEntry, 1);
status->devices = g_list_prepend (status->devices, entry);
entry->device_info = device_info;
closure = g_cclosure_new (G_CALLBACK (gimp_device_status_update_entry),
entry, NULL);
g_object_watch_closure (G_OBJECT (status), closure);
g_signal_connect_closure (device_info, "changed", closure, FALSE);
entry->table = gtk_table_new (2, 7, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (entry->table), 6);
gtk_box_pack_start (GTK_BOX (status->vbox), entry->table,
FALSE, FALSE, 0);
gtk_widget_show (entry->table);
/* the device name */
if (device_info->display == gdk_display_get_default ())
name = g_strdup (gimp_object_get_name (GIMP_OBJECT (device_info)));
else
name = g_strdup_printf ("%s (%s)",
gimp_object_get_name (GIMP_OBJECT (device_info)),
gdk_display_get_name (device_info->display));
entry->label = gtk_label_new (name);
g_free (name);
gimp_label_set_attributes (GTK_LABEL (entry->label),
PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
-1);
gtk_widget_set_size_request (entry->label, -1, CELL_SIZE);
gtk_misc_set_alignment (GTK_MISC (entry->label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (entry->table), entry->label,
1, 7, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (entry->label);
/* the arrow */
entry->arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
gtk_widget_set_size_request (entry->arrow, CELL_SIZE, CELL_SIZE);
gtk_table_attach (GTK_TABLE (entry->table), entry->arrow,
0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
hbox = gtk_hbox_new (FALSE, 0);
gtk_widget_set_size_request (hbox, CELL_SIZE, CELL_SIZE);
gtk_table_attach (GTK_TABLE (entry->table), hbox,
0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (hbox);
/* the tool */
entry->tool = gimp_prop_preview_new (G_OBJECT (context),
"tool", CELL_SIZE);
GIMP_VIEW (entry->tool)->clickable = TRUE;
gtk_table_attach (GTK_TABLE (entry->table), entry->tool,
1, 2, 1, 2, 0, 0, 0, 0);
gtk_widget_show (entry->tool);
g_signal_connect (entry->tool, "clicked",
G_CALLBACK (gimp_device_status_preview_clicked),
"gimp-tool-list|gimp-tool-grid");
/* the foreground color */
entry->foreground = gimp_prop_color_area_new (G_OBJECT (context),
"foreground",
CELL_SIZE, CELL_SIZE,
GIMP_COLOR_AREA_FLAT);
gtk_widget_add_events (entry->foreground,
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
gtk_table_attach (GTK_TABLE (entry->table), entry->foreground,
2, 3, 1, 2, 0, 0, 0, 0);
gtk_widget_show (entry->foreground);
/* the background color */
entry->background = gimp_prop_color_area_new (G_OBJECT (context),
"background",
CELL_SIZE, CELL_SIZE,
GIMP_COLOR_AREA_FLAT);
gtk_widget_add_events (entry->background,
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
gtk_table_attach (GTK_TABLE (entry->table), entry->background,
3, 4, 1, 2, 0, 0, 0, 0);
gtk_widget_show (entry->background);
/* the brush */
entry->brush = gimp_prop_preview_new (G_OBJECT (context),
"brush", CELL_SIZE);
GIMP_VIEW (entry->brush)->clickable = TRUE;
GIMP_VIEW (entry->brush)->show_popup = TRUE;
gtk_table_attach (GTK_TABLE (entry->table), entry->brush,
4, 5, 1, 2, 0, 0, 0, 0);
gtk_widget_show (entry->brush);
g_signal_connect (entry->brush, "clicked",
G_CALLBACK (gimp_device_status_preview_clicked),
"gimp-brush-grid|gimp-brush-list");
/* the pattern */
entry->pattern = gimp_prop_preview_new (G_OBJECT (context),
"pattern", CELL_SIZE);
GIMP_VIEW (entry->pattern)->clickable = TRUE;
GIMP_VIEW (entry->pattern)->show_popup = TRUE;
gtk_table_attach (GTK_TABLE (entry->table), entry->pattern,
5, 6, 1, 2, 0, 0, 0, 0);
gtk_widget_show (entry->pattern);
g_signal_connect (entry->pattern, "clicked",
G_CALLBACK (gimp_device_status_preview_clicked),
"gimp-pattern-grid|gimp-pattern-list");
/* the gradient */
entry->gradient = gimp_prop_preview_new (G_OBJECT (context),
"gradient", 2 * CELL_SIZE);
GIMP_VIEW (entry->gradient)->clickable = TRUE;
GIMP_VIEW (entry->gradient)->show_popup = TRUE;
gtk_table_attach (GTK_TABLE (entry->table), entry->gradient,
6, 7, 1, 2, 0, 0, 0, 0);
gtk_widget_show (entry->gradient);
g_signal_connect (entry->gradient, "clicked",
G_CALLBACK (gimp_device_status_preview_clicked),
"gimp-gradient-list|gimp-gradient-grid");
gimp_device_status_update_entry (device_info, entry);
}
static void
gimp_device_status_device_remove (GimpContainer *devices,
GimpDeviceInfo *device_info,
GimpDeviceStatus *status)
{
GList *list;
for (list = status->devices; list; list = list->next)
{
GimpDeviceStatusEntry *entry = list->data;
if (entry->device_info == device_info)
{
status->devices = g_list_remove (status->devices, entry);
g_signal_handlers_disconnect_by_func (entry->device_info,
gimp_device_status_update_entry,
entry);
g_free (entry);
return;
}
}
}
GtkWidget *
gimp_device_status_new (Gimp *gimp)
{
GimpDeviceStatus *status;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
status = g_object_new (GIMP_TYPE_DEVICE_STATUS, NULL);
status->gimp = gimp;
gimp_device_status_update (status);
return GTK_WIDGET (status);
return g_object_new (GIMP_TYPE_DEVICE_STATUS,
"gimp", gimp,
NULL);
}
void
gimp_device_status_update (GimpDeviceStatus *status)
{
gint i;
GList *list;
g_return_if_fail (GIMP_IS_DEVICE_STATUS (status));
status->current_device = gimp_devices_get_current (status->gimp);
for (i = 0; i < status->num_devices; i++)
for (list = status->devices; list; list = list->next)
{
GimpDeviceStatusEntry *entry = &status->entries[i];
GimpDeviceStatusEntry *entry = list->data;
if (entry->device == status->current_device)
if (entry->device_info->device &&
entry->device_info->device == status->current_device)
gtk_widget_show (entry->arrow);
else
gtk_widget_hide (entry->arrow);
@ -353,16 +461,9 @@ static void
gimp_device_status_update_entry (GimpDeviceInfo *device_info,
GimpDeviceStatusEntry *entry)
{
if (device_info->device->mode == GDK_MODE_DISABLED)
if (! device_info->device || device_info->device->mode == GDK_MODE_DISABLED)
{
gtk_widget_hide (entry->separator);
gtk_widget_hide (entry->label);
gtk_widget_hide (entry->tool);
gtk_widget_hide (entry->foreground);
gtk_widget_hide (entry->background);
gtk_widget_hide (entry->brush);
gtk_widget_hide (entry->pattern);
gtk_widget_hide (entry->gradient);
gtk_widget_hide (entry->table);
}
else
{
@ -371,15 +472,6 @@ gimp_device_status_update_entry (GimpDeviceInfo *device_info,
guchar r, g, b;
gchar buf[64];
gtk_widget_show (entry->separator);
gtk_widget_show (entry->label);
gtk_widget_show (entry->tool);
gtk_widget_show (entry->foreground);
gtk_widget_show (entry->background);
gtk_widget_show (entry->brush);
gtk_widget_show (entry->pattern);
gtk_widget_show (entry->gradient);
gimp_context_get_foreground (context, &color);
gimp_rgb_get_uchar (&color, &r, &g, &b);
g_snprintf (buf, sizeof (buf), _("Foreground: %d, %d, %d"), r, g, b);
@ -389,6 +481,8 @@ gimp_device_status_update_entry (GimpDeviceInfo *device_info,
gimp_rgb_get_uchar (&color, &r, &g, &b);
g_snprintf (buf, sizeof (buf), _("Background: %d, %d, %d"), r, g, b);
gimp_help_set_help_data (entry->background, buf, NULL);
gtk_widget_show (entry->table);
}
}

View File

@ -39,18 +39,17 @@ typedef struct _GimpDeviceStatusClass GimpDeviceStatusClass;
struct _GimpDeviceStatus
{
GimpEditor parent_instance;
GimpEditor parent_instance;
Gimp *gimp;
GdkDevice *current_device;
Gimp *gimp;
GdkDevice *current_device;
gint num_devices;
GimpDeviceStatusEntry *entries;
GList *devices;
GtkWidget *table;
GtkWidget *vbox;
GtkWidget *save_button;
GtkWidget *edit_button;
GtkWidget *save_button;
GtkWidget *edit_button;
};
struct _GimpDeviceStatusClass