[gimp/metadata-browser] app: add more modifier utility functions to gimpwidgets-utils.[ch]
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] app: add more modifier utility functions to gimpwidgets-utils.[ch]
- Date: Fri, 2 Dec 2011 02:07:30 +0000 (UTC)
commit 35dceae931f7399f9c34a5c07d75f4e190b3ea3e
Author: Michael Natterer <mitch gimp org>
Date: Wed Oct 5 19:15:17 2011 +0200
app: add more modifier utility functions to gimpwidgets-utils.[ch]
- gimp_modifiers_to_channel_op() translates a modifier state to REPLACE,
ADD, SUBTRACT or INTERSECT.
- gimp_replace_virtual_modifiers() uses gdk_keymap_add_virtual_modifiers()
to replace the physical bits in a modifier state to their virtual
counterparts (and not just adds the virtual ones like the GDK
function).
app/widgets/gimpwidgets-utils.c | 63 +++++++++++++++++++++++++++++++++++++++
app/widgets/gimpwidgets-utils.h | 5 +++
2 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index 22d9407..4cf9b34 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -616,6 +616,69 @@ gimp_suggest_modifiers (const gchar *message,
}
#undef BUF_SIZE
+GimpChannelOps
+gimp_modifiers_to_channel_op (GtkWidget *widget,
+ GdkModifierType modifiers)
+{
+ GdkModifierType extend_mask;
+ GdkModifierType modify_mask;
+
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), GIMP_CHANNEL_OP_REPLACE);
+
+ extend_mask =
+ gtk_widget_get_modifier_mask (widget,
+ GDK_MODIFIER_INTENT_EXTEND_SELECTION);
+ modify_mask =
+ gtk_widget_get_modifier_mask (widget,
+ GDK_MODIFIER_INTENT_MODIFY_SELECTION);
+
+ if (modifiers & extend_mask)
+ {
+ if (modifiers & modify_mask)
+ {
+ return GIMP_CHANNEL_OP_INTERSECT;
+ }
+ else
+ {
+ return GIMP_CHANNEL_OP_ADD;
+ }
+ }
+ else if (modifiers & modify_mask)
+ {
+ return GIMP_CHANNEL_OP_SUBTRACT;
+ }
+
+ return GIMP_CHANNEL_OP_REPLACE;
+}
+
+GdkModifierType
+gimp_replace_virtual_modifiers (GdkModifierType modifiers)
+{
+ GdkDisplay *display = gdk_display_get_default ();
+ GdkModifierType result = 0;
+ gint i;
+
+ for (i = 0; i < 8; i++)
+ {
+ GdkModifierType real = 1 << i;
+
+ if (modifiers & real)
+ {
+ GdkModifierType virtual = real;
+
+ gdk_keymap_add_virtual_modifiers (gdk_keymap_get_for_display (display),
+ &virtual);
+
+ if (virtual == real)
+ result |= virtual;
+ else
+ result |= virtual & ~real;
+ }
+ }
+
+ return result;
+}
+
/**
* gimp_get_screen_resolution:
* @screen: a #GdkScreen or %NULL
diff --git a/app/widgets/gimpwidgets-utils.h b/app/widgets/gimpwidgets-utils.h
index fcfdbe2..7a64523 100644
--- a/app/widgets/gimpwidgets-utils.h
+++ b/app/widgets/gimpwidgets-utils.h
@@ -50,6 +50,7 @@ GtkIconSize gimp_get_icon_size (GtkWidget *widget
gint width,
gint height);
GimpTabStyle gimp_preview_tab_style_to_icon (GimpTabStyle tab_style);
+
const gchar * gimp_get_mod_separator (void);
const gchar * gimp_get_mod_string (GdkModifierType modifiers);
gchar * gimp_suggest_modifiers (const gchar *message,
@@ -57,6 +58,10 @@ gchar * gimp_suggest_modifiers (const gchar *messag
const gchar *shift_format,
const gchar *control_format,
const gchar *alt_format);
+GimpChannelOps gimp_modifiers_to_channel_op (GtkWidget *widget,
+ GdkModifierType modifiers);
+GdkModifierType gimp_replace_virtual_modifiers (GdkModifierType modifiers);
+
void gimp_get_screen_resolution (GdkScreen *screen,
gdouble *xres,
gdouble *yres);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]