forked from AuroraMiddleware/gtk
Merge branch 'color-picker' into 'master'
Color picker See merge request GNOME/gtk!273
This commit is contained in:
commit
2c5f2a2bcb
@ -24,7 +24,9 @@
|
||||
#include "gtkcolorscaleprivate.h"
|
||||
#include "gtkcolorswatchprivate.h"
|
||||
#include "gtkcolorutils.h"
|
||||
#include "gtkcolorpickerprivate.h"
|
||||
#include "gtkgrid.h"
|
||||
#include "gtkbutton.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtkorientable.h"
|
||||
#include "gtkentry.h"
|
||||
@ -61,6 +63,9 @@ struct _GtkColorEditorPrivate
|
||||
GtkAdjustment *v_adj;
|
||||
GtkAdjustment *a_adj;
|
||||
|
||||
GtkWidget *picker_button;
|
||||
GtkColorPicker *picker;
|
||||
|
||||
gint popup_position;
|
||||
|
||||
guint text_changed : 1;
|
||||
@ -337,6 +342,36 @@ scaled_adjustment (GtkAdjustment *a,
|
||||
return as;
|
||||
}
|
||||
|
||||
static void
|
||||
color_picked (GObject *source,
|
||||
GAsyncResult *res,
|
||||
gpointer data)
|
||||
{
|
||||
GtkColorPicker *picker = GTK_COLOR_PICKER (source);
|
||||
GtkColorEditor *editor = data;
|
||||
GError *error = NULL;
|
||||
GdkRGBA *color;
|
||||
|
||||
color = gtk_color_picker_pick_finish (picker, res, &error);
|
||||
if (color == NULL)
|
||||
{
|
||||
g_warning ("Picking color failed: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (editor), color);
|
||||
gdk_rgba_free (color);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pick_color (GtkButton *button,
|
||||
GtkColorEditor *editor)
|
||||
{
|
||||
gtk_color_picker_pick (editor->priv->picker, color_picked, editor);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_editor_init (GtkColorEditor *editor)
|
||||
{
|
||||
@ -385,6 +420,10 @@ gtk_color_editor_init (GtkColorEditor *editor)
|
||||
gtk_widget_add_controller (editor->priv->a_entry, controller);
|
||||
|
||||
gtk_style_context_remove_class (gtk_widget_get_style_context (editor->priv->swatch), "activatable");
|
||||
|
||||
editor->priv->picker = gtk_color_picker_new ();
|
||||
if (editor->priv->picker == NULL)
|
||||
gtk_widget_hide (editor->priv->picker_button);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -393,6 +432,7 @@ gtk_color_editor_dispose (GObject *object)
|
||||
GtkColorEditor *editor = GTK_COLOR_EDITOR (object);
|
||||
|
||||
dismiss_current_popup (editor);
|
||||
g_clear_object (&editor->priv->picker);
|
||||
|
||||
G_OBJECT_CLASS (gtk_color_editor_parent_class)->dispose (object);
|
||||
}
|
||||
@ -495,6 +535,7 @@ gtk_color_editor_class_init (GtkColorEditorClass *class)
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkColorEditor, s_adj);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkColorEditor, v_adj);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkColorEditor, a_adj);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkColorEditor, picker_button);
|
||||
|
||||
gtk_widget_class_bind_template_callback (widget_class, hsv_changed);
|
||||
gtk_widget_class_bind_template_callback (widget_class, dismiss_current_popup);
|
||||
@ -503,6 +544,7 @@ gtk_color_editor_class_init (GtkColorEditorClass *class)
|
||||
gtk_widget_class_bind_template_callback (widget_class, entry_apply);
|
||||
gtk_widget_class_bind_template_callback (widget_class, entry_focus_changed);
|
||||
gtk_widget_class_bind_template_callback (widget_class, popup_edit);
|
||||
gtk_widget_class_bind_template_callback (widget_class, pick_color);
|
||||
}
|
||||
|
||||
static void
|
||||
|
59
gtk/gtkcolorpicker.c
Normal file
59
gtk/gtkcolorpicker.c
Normal file
@ -0,0 +1,59 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2018, Red Hat, Inc
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkcolorpickerprivate.h"
|
||||
#include "gtkcolorpickerportalprivate.h"
|
||||
#include "gtkcolorpickershellprivate.h"
|
||||
#include "gtkprivate.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
|
||||
G_DEFINE_INTERFACE_WITH_CODE (GtkColorPicker, gtk_color_picker, G_TYPE_OBJECT,
|
||||
g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_INITABLE);)
|
||||
|
||||
static void
|
||||
gtk_color_picker_default_init (GtkColorPickerInterface *iface)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
gtk_color_picker_pick (GtkColorPicker *picker,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GTK_COLOR_PICKER_GET_INTERFACE (picker)->pick (picker, callback, user_data);
|
||||
}
|
||||
|
||||
GdkRGBA *
|
||||
gtk_color_picker_pick_finish (GtkColorPicker *picker,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
return GTK_COLOR_PICKER_GET_INTERFACE (picker)->pick_finish (picker, res, error);
|
||||
}
|
||||
|
||||
GtkColorPicker *
|
||||
gtk_color_picker_new (void)
|
||||
{
|
||||
if (gtk_should_use_portal ())
|
||||
return gtk_color_picker_portal_new ();
|
||||
else
|
||||
return gtk_color_picker_shell_new ();
|
||||
}
|
||||
|
239
gtk/gtkcolorpickerportal.c
Normal file
239
gtk/gtkcolorpickerportal.c
Normal file
@ -0,0 +1,239 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2018, Red Hat, Inc
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkcolorpickerportalprivate.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
struct _GtkColorPickerPortal
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
GDBusProxy *portal_proxy;
|
||||
guint portal_signal_id;
|
||||
GTask *task;
|
||||
};
|
||||
|
||||
struct _GtkColorPickerPortalClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
static GInitableIface *initable_parent_iface;
|
||||
static void gtk_color_picker_portal_initable_iface_init (GInitableIface *iface);
|
||||
static void gtk_color_picker_portal_iface_init (GtkColorPickerInterface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkColorPickerPortal, gtk_color_picker_portal, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, gtk_color_picker_portal_initable_iface_init)
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_PICKER, gtk_color_picker_portal_iface_init))
|
||||
|
||||
static gboolean
|
||||
gtk_color_picker_portal_initable_init (GInitable *initable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
GtkColorPickerPortal *picker = GTK_COLOR_PICKER_PORTAL (initable);
|
||||
char *owner;
|
||||
GVariant *ret;
|
||||
guint version;
|
||||
|
||||
picker->portal_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
NULL,
|
||||
"org.freedesktop.portal.Desktop",
|
||||
"/org/freedesktop/portal/desktop",
|
||||
"org.freedesktop.portal.Screenshot",
|
||||
NULL,
|
||||
error);
|
||||
|
||||
if (picker->portal_proxy == NULL)
|
||||
{
|
||||
g_debug ("Failed to create screnshot portal proxy");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
owner = g_dbus_proxy_get_name_owner (picker->portal_proxy);
|
||||
if (owner == NULL)
|
||||
{
|
||||
g_debug ("org.freedesktop.portal.Screenshot not provided");
|
||||
g_clear_object (&picker->portal_proxy);
|
||||
return FALSE;
|
||||
}
|
||||
g_free (owner);
|
||||
|
||||
ret = g_dbus_proxy_get_cached_property (picker->portal_proxy, "version");
|
||||
g_variant_get (ret, "u", &version);
|
||||
g_variant_unref (ret);
|
||||
if (version != 2)
|
||||
{
|
||||
g_debug ("Screenshot portal version: %u", version);
|
||||
g_clear_object (&picker->portal_proxy);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_portal_initable_iface_init (GInitableIface *iface)
|
||||
{
|
||||
initable_parent_iface = g_type_interface_peek_parent (iface);
|
||||
iface->init = gtk_color_picker_portal_initable_init;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_portal_init (GtkColorPickerPortal *picker)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_portal_finalize (GObject *object)
|
||||
{
|
||||
GtkColorPickerPortal *picker = GTK_COLOR_PICKER_PORTAL (object);
|
||||
|
||||
g_clear_object (&picker->portal_proxy);
|
||||
|
||||
G_OBJECT_CLASS (gtk_color_picker_portal_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_portal_class_init (GtkColorPickerPortalClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
|
||||
object_class->finalize = gtk_color_picker_portal_finalize;
|
||||
}
|
||||
|
||||
GtkColorPicker *
|
||||
gtk_color_picker_portal_new (void)
|
||||
{
|
||||
return GTK_COLOR_PICKER (g_initable_new (GTK_TYPE_COLOR_PICKER_PORTAL, NULL, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
portal_response_received (GDBusConnection *connection,
|
||||
const char *sender_name,
|
||||
const char *object_path,
|
||||
const char *interface_name,
|
||||
const char *signal_name,
|
||||
GVariant *parameters,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkColorPickerPortal *picker = user_data;
|
||||
guint32 response;
|
||||
GVariant *ret;
|
||||
|
||||
g_dbus_connection_signal_unsubscribe (connection, picker->portal_signal_id);
|
||||
picker->portal_signal_id = 0;
|
||||
|
||||
g_variant_get (parameters, "(u@a{sv})", &response, &ret);
|
||||
|
||||
if (response == 0)
|
||||
{
|
||||
GdkRGBA c;
|
||||
|
||||
c.alpha = 1.0;
|
||||
if (g_variant_lookup (ret, "color", "(ddd)", &c.red, &c.green, &c.blue))
|
||||
g_task_return_pointer (picker->task, gdk_rgba_copy (&c), (GDestroyNotify)gdk_rgba_free);
|
||||
else
|
||||
g_task_return_new_error (picker->task,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"No color received");
|
||||
}
|
||||
else
|
||||
g_task_return_new_error (picker->task,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"PickColor error");
|
||||
|
||||
g_variant_unref (ret);
|
||||
|
||||
g_clear_object (&picker->task);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_portal_pick (GtkColorPicker *cp,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkColorPickerPortal *picker = GTK_COLOR_PICKER_PORTAL (cp);
|
||||
GVariantBuilder options;
|
||||
char *token;
|
||||
GDBusConnection *connection;
|
||||
char *sender;
|
||||
char *handle;
|
||||
int i;
|
||||
|
||||
if (picker->task)
|
||||
return;
|
||||
|
||||
picker->task = g_task_new (picker, NULL, callback, user_data);
|
||||
|
||||
connection = g_dbus_proxy_get_connection (picker->portal_proxy);
|
||||
|
||||
token = g_strdup_printf ("gtk%d", g_random_int_range (0, G_MAXINT));
|
||||
sender = g_strdup (g_dbus_connection_get_unique_name (connection) + 1);
|
||||
for (i = 0; sender[i]; i++)
|
||||
if (sender[i] == '.')
|
||||
sender[i] = '_';
|
||||
|
||||
handle = g_strdup_printf ("/org/freedesktop/portal/desktop/request/%s/%s", sender, token);
|
||||
picker->portal_signal_id = g_dbus_connection_signal_subscribe (connection,
|
||||
"org.freedesktop.portal.Desktop",
|
||||
"org.freedesktop.portal.Request",
|
||||
"Response",
|
||||
handle,
|
||||
NULL,
|
||||
G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
|
||||
portal_response_received,
|
||||
picker,
|
||||
NULL);
|
||||
|
||||
g_free (handle);
|
||||
|
||||
g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
|
||||
g_variant_builder_add (&options, "{sv}", "handle_token", g_variant_new_string (token));
|
||||
g_free (token);
|
||||
|
||||
g_dbus_proxy_call (picker->portal_proxy,
|
||||
"PickColor",
|
||||
g_variant_new ("(sa{sv})", "", &options),
|
||||
0,
|
||||
-1,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static GdkRGBA *
|
||||
gtk_color_picker_portal_pick_finish (GtkColorPicker *cp,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (res, cp), NULL);
|
||||
|
||||
return g_task_propagate_pointer (G_TASK (res), error);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_portal_iface_init (GtkColorPickerInterface *iface)
|
||||
{
|
||||
iface->pick = gtk_color_picker_portal_pick;
|
||||
iface->pick_finish = gtk_color_picker_portal_pick_finish;
|
||||
}
|
41
gtk/gtkcolorpickerportalprivate.h
Normal file
41
gtk/gtkcolorpickerportalprivate.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2018 Red Hat, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This Library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This Library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_COLOR_PICKER_PORTAL_H__
|
||||
#define __GTK_COLOR_PICKER_PORTAL_H__
|
||||
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <gtk/gtkcolorpickerprivate.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
#define GTK_TYPE_COLOR_PICKER_PORTAL gtk_color_picker_portal_get_type ()
|
||||
G_DECLARE_FINAL_TYPE (GtkColorPickerPortal, gtk_color_picker_portal, GTK, COLOR_PICKER_PORTAL, GObject)
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkColorPicker * gtk_color_picker_portal_new (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_COLOR_PICKER_PORTAL_H__ */
|
69
gtk/gtkcolorpickerprivate.h
Normal file
69
gtk/gtkcolorpickerprivate.h
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2018 Red Hat, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This Library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This Library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_COLOR_PICKER_H__
|
||||
#define __GTK_COLOR_PICKER_H__
|
||||
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <gtk/gtkwindow.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
#define GTK_TYPE_COLOR_PICKER (gtk_color_picker_get_type ())
|
||||
#define GTK_COLOR_PICKER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_COLOR_PICKER, GtkColorPicker))
|
||||
#define GTK_IS_COLOR_PICKER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_COLOR_PICKER))
|
||||
#define GTK_COLOR_PICKER_GET_INTERFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), GTK_TYPE_COLOR_PICKER, GtkColorPickerInterface))
|
||||
|
||||
|
||||
typedef struct _GtkColorPicker GtkColorPicker;
|
||||
typedef struct _GtkColorPickerInterface GtkColorPickerInterface;
|
||||
|
||||
struct _GtkColorPickerInterface {
|
||||
GTypeInterface g_iface;
|
||||
|
||||
void (* pick) (GtkColorPicker *picker,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
GdkRGBA * (* pick_finish) (GtkColorPicker *picker,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
};
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gtk_color_picker_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkColorPicker * gtk_color_picker_new (void);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_color_picker_pick (GtkColorPicker *picker,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GdkRGBA * gtk_color_picker_pick_finish (GtkColorPicker *picker,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_COLOR_PICKER_H__ */
|
183
gtk/gtkcolorpickershell.c
Normal file
183
gtk/gtkcolorpickershell.c
Normal file
@ -0,0 +1,183 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2018, Red Hat, Inc
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkcolorpickershellprivate.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
struct _GtkColorPickerShell
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
GDBusProxy *shell_proxy;
|
||||
GTask *task;
|
||||
};
|
||||
|
||||
struct _GtkColorPickerShellClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
static GInitableIface *initable_parent_iface;
|
||||
static void gtk_color_picker_shell_initable_iface_init (GInitableIface *iface);
|
||||
static void gtk_color_picker_shell_iface_init (GtkColorPickerInterface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkColorPickerShell, gtk_color_picker_shell, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, gtk_color_picker_shell_initable_iface_init)
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_PICKER, gtk_color_picker_shell_iface_init))
|
||||
|
||||
static gboolean
|
||||
gtk_color_picker_shell_initable_init (GInitable *initable,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
GtkColorPickerShell *picker = GTK_COLOR_PICKER_SHELL (initable);
|
||||
char *owner;
|
||||
|
||||
picker->shell_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
NULL,
|
||||
"org.gnome.Shell.Screenshot",
|
||||
"/org/gnome/Shell/Screenshot",
|
||||
"org.gnome.Shell.Screenshot",
|
||||
NULL,
|
||||
error);
|
||||
|
||||
if (picker->shell_proxy == NULL)
|
||||
{
|
||||
g_debug ("Failed to create shell screenshot proxy");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
owner = g_dbus_proxy_get_name_owner (picker->shell_proxy);
|
||||
if (owner == NULL)
|
||||
{
|
||||
g_debug ("org.gnome.Shell.Screenshot not provided");
|
||||
g_clear_object (&picker->shell_proxy);
|
||||
return FALSE;
|
||||
}
|
||||
g_free (owner);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_shell_initable_iface_init (GInitableIface *iface)
|
||||
{
|
||||
initable_parent_iface = g_type_interface_peek_parent (iface);
|
||||
iface->init = gtk_color_picker_shell_initable_init;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_shell_init (GtkColorPickerShell *picker)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_shell_finalize (GObject *object)
|
||||
{
|
||||
GtkColorPickerShell *picker = GTK_COLOR_PICKER_SHELL (object);
|
||||
|
||||
g_clear_object (&picker->shell_proxy);
|
||||
|
||||
G_OBJECT_CLASS (gtk_color_picker_shell_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_shell_class_init (GtkColorPickerShellClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
|
||||
object_class->finalize = gtk_color_picker_shell_finalize;
|
||||
}
|
||||
|
||||
GtkColorPicker *
|
||||
gtk_color_picker_shell_new (void)
|
||||
{
|
||||
return GTK_COLOR_PICKER (g_initable_new (GTK_TYPE_COLOR_PICKER_SHELL, NULL, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
color_picked (GObject *source,
|
||||
GAsyncResult *res,
|
||||
gpointer data)
|
||||
{
|
||||
GtkColorPickerShell *picker = GTK_COLOR_PICKER_SHELL (data);
|
||||
GError *error = NULL;
|
||||
GVariant *ret;
|
||||
|
||||
ret = g_dbus_proxy_call_finish (picker->shell_proxy, res, &error);
|
||||
|
||||
if (ret == NULL)
|
||||
{
|
||||
g_task_return_error (picker->task, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
GdkRGBA c;
|
||||
|
||||
c.alpha = 1;
|
||||
if (!g_variant_lookup (ret, "color", "(ddd)", &c.red, &c.green, &c.blue))
|
||||
g_task_return_new_error (picker->task, G_IO_ERROR, G_IO_ERROR_FAILED, "No color received");
|
||||
else
|
||||
g_task_return_pointer (picker->task, gdk_rgba_copy (&c), (GDestroyNotify)gdk_rgba_free);
|
||||
|
||||
g_variant_unref (ret);
|
||||
}
|
||||
|
||||
g_clear_object (&picker->task);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_shell_pick (GtkColorPicker *cp,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkColorPickerShell *picker = GTK_COLOR_PICKER_SHELL (cp);
|
||||
|
||||
if (picker->task)
|
||||
return;
|
||||
|
||||
picker->task = g_task_new (picker, NULL, callback, user_data);
|
||||
|
||||
g_dbus_proxy_call (picker->shell_proxy,
|
||||
"PickColor",
|
||||
NULL,
|
||||
0,
|
||||
-1,
|
||||
NULL,
|
||||
color_picked,
|
||||
picker);
|
||||
}
|
||||
|
||||
static GdkRGBA *
|
||||
gtk_color_picker_shell_pick_finish (GtkColorPicker *cp,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (res, cp), NULL);
|
||||
|
||||
return g_task_propagate_pointer (G_TASK (res), error);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_picker_shell_iface_init (GtkColorPickerInterface *iface)
|
||||
{
|
||||
iface->pick = gtk_color_picker_shell_pick;
|
||||
iface->pick_finish = gtk_color_picker_shell_pick_finish;
|
||||
}
|
41
gtk/gtkcolorpickershellprivate.h
Normal file
41
gtk/gtkcolorpickershellprivate.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 2018 Red Hat, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This Library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This Library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_COLOR_PICKER_SHELL_H__
|
||||
#define __GTK_COLOR_PICKER_SHELL_H__
|
||||
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <gtk/gtkcolorpickerprivate.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
#define GTK_TYPE_COLOR_PICKER_SHELL gtk_color_picker_shell_get_type ()
|
||||
G_DECLARE_FINAL_TYPE (GtkColorPickerShell, gtk_color_picker_shell, GTK, COLOR_PICKER_SHELL, GObject)
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkColorPicker * gtk_color_picker_shell_new (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_COLOR_PICKER_SHELL_H__ */
|
@ -30,6 +30,9 @@ gtk_private_sources = files([
|
||||
'gtkcellareaboxcontext.c',
|
||||
'gtkcoloreditor.c',
|
||||
'gtkcolorplane.c',
|
||||
'gtkcolorpicker.c',
|
||||
'gtkcolorpickerportal.c',
|
||||
'gtkcolorpickershell.c',
|
||||
'gtkcolorscale.c',
|
||||
'gtkcolorswatch.c',
|
||||
'gtkcssanimatedstyle.c',
|
||||
|
@ -38,6 +38,20 @@
|
||||
<property name="margin-end">30</property>
|
||||
<property name="row-spacing">12</property>
|
||||
<property name="column-spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="picker_button">
|
||||
<property name="icon-name">color-select-symbolic</property>
|
||||
<property name="tooltip-text" translatable="yes">Pick a color from the screen</property>
|
||||
<signal name="clicked" handler="pick_color"/>
|
||||
<style>
|
||||
<class name="circular"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left-attach">0</property>
|
||||
<property name="top-attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkColorSwatch" id="swatch">
|
||||
<property name="name">editor-color-sample</property>
|
||||
|
@ -1,7 +1,7 @@
|
||||
window1
|
||||
"window"
|
||||
index: 0
|
||||
name:
|
||||
name: Page 1
|
||||
state: enabled resizable sensitive showing visible
|
||||
toolkit: gtk
|
||||
window-type: normal
|
||||
@ -12,7 +12,7 @@ window1
|
||||
"push button"
|
||||
parent: unnamed-GtkContainerAccessible-0
|
||||
index: 0
|
||||
name: Button 1
|
||||
name: Page 1
|
||||
state: enabled focusable sensitive showing visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
@ -28,7 +28,7 @@ window1
|
||||
"push button"
|
||||
parent: unnamed-GtkContainerAccessible-1
|
||||
index: 0
|
||||
name: Button 2
|
||||
name: Page 2
|
||||
state: enabled focusable sensitive visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
|
@ -768,10 +768,26 @@ window1
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
picker_button
|
||||
"push button"
|
||||
parent: grid
|
||||
index: 0
|
||||
description: Pick a color from the screen
|
||||
state: enabled focusable sensitive has-tooltip
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
<AtkImage>
|
||||
image size: 16 x 16
|
||||
image description: (null)
|
||||
<AtkAction>
|
||||
action 0 name: click
|
||||
action 0 description: Clicks the button
|
||||
swatch
|
||||
"radio button"
|
||||
parent: grid
|
||||
index: 0
|
||||
index: 1
|
||||
state: enabled sensitive visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
@ -787,7 +803,7 @@ window1
|
||||
entry
|
||||
"text"
|
||||
parent: grid
|
||||
index: 1
|
||||
index: 2
|
||||
name: Color Name
|
||||
state: editable enabled focusable sensitive single-line visible
|
||||
toolkit: gtk
|
||||
@ -829,7 +845,7 @@ window1
|
||||
h_slider
|
||||
"color chooser"
|
||||
parent: grid
|
||||
index: 2
|
||||
index: 3
|
||||
name: Hue
|
||||
state: enabled focusable sensitive vertical visible
|
||||
toolkit: gtk
|
||||
@ -843,7 +859,7 @@ window1
|
||||
a_slider
|
||||
"color chooser"
|
||||
parent: grid
|
||||
index: 3
|
||||
index: 4
|
||||
name: Alpha
|
||||
state: enabled focusable horizontal sensitive visible
|
||||
toolkit: gtk
|
||||
@ -857,7 +873,7 @@ window1
|
||||
sv_plane
|
||||
"color chooser"
|
||||
parent: grid
|
||||
index: 4
|
||||
index: 5
|
||||
name: Color Plane
|
||||
state: enabled focusable sensitive visible
|
||||
toolkit: gtk
|
||||
|
@ -7,14 +7,6 @@ window1
|
||||
<AtkComponent>
|
||||
layer: window
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-0
|
||||
"panel"
|
||||
parent: window1
|
||||
state: enabled sensitive showing visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
menubar1
|
||||
"menu bar"
|
||||
parent: window1
|
||||
|
@ -7,14 +7,6 @@ window1
|
||||
<AtkComponent>
|
||||
layer: window
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-0
|
||||
"panel"
|
||||
parent: window1
|
||||
state: enabled sensitive showing visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
menubutton
|
||||
"toggle button"
|
||||
parent: window1
|
||||
|
@ -7,15 +7,7 @@ window1
|
||||
<AtkComponent>
|
||||
layer: window
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-0
|
||||
"panel"
|
||||
parent: window1
|
||||
state: enabled sensitive showing visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkPopoverAccessible-1
|
||||
unnamed-GtkPopoverAccessible-0
|
||||
"panel"
|
||||
parent: menubutton
|
||||
popup-for: menubutton
|
||||
@ -24,53 +16,53 @@ window1
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkStackAccessible-2
|
||||
unnamed-GtkStackAccessible-1
|
||||
"panel"
|
||||
parent: unnamed-GtkWidgetAccessible-3
|
||||
parent: unnamed-GtkWidgetAccessible-2
|
||||
state: enabled sensitive visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-4
|
||||
unnamed-GtkContainerAccessible-3
|
||||
"filler"
|
||||
parent: unnamed-GtkStackAccessible-2
|
||||
parent: unnamed-GtkStackAccessible-1
|
||||
index: 0
|
||||
state: enabled sensitive vertical visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-5
|
||||
unnamed-GtkContainerAccessible-4
|
||||
"filler"
|
||||
parent: unnamed-GtkContainerAccessible-4
|
||||
parent: unnamed-GtkContainerAccessible-3
|
||||
index: 0
|
||||
state: enabled sensitive vertical visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-6
|
||||
unnamed-GtkContainerAccessible-5
|
||||
"filler"
|
||||
parent: unnamed-GtkContainerAccessible-5
|
||||
parent: unnamed-GtkContainerAccessible-4
|
||||
index: 0
|
||||
state: enabled sensitive vertical visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-7
|
||||
unnamed-GtkContainerAccessible-6
|
||||
"filler"
|
||||
parent: unnamed-GtkContainerAccessible-6
|
||||
parent: unnamed-GtkContainerAccessible-5
|
||||
index: 0
|
||||
state: enabled sensitive vertical visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkButtonAccessible-8
|
||||
unnamed-GtkButtonAccessible-7
|
||||
"push button"
|
||||
parent: unnamed-GtkContainerAccessible-7
|
||||
parent: unnamed-GtkContainerAccessible-6
|
||||
index: 0
|
||||
name: New
|
||||
state: enabled focusable sensitive visible
|
||||
|
@ -7,15 +7,7 @@ window1
|
||||
<AtkComponent>
|
||||
layer: window
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-0
|
||||
"panel"
|
||||
parent: window1
|
||||
state: enabled sensitive showing visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkPopoverAccessible-1
|
||||
unnamed-GtkPopoverAccessible-0
|
||||
"panel"
|
||||
parent: menubutton
|
||||
popup-for: menubutton
|
||||
@ -24,53 +16,53 @@ window1
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkStackAccessible-2
|
||||
unnamed-GtkStackAccessible-1
|
||||
"panel"
|
||||
parent: unnamed-GtkWidgetAccessible-3
|
||||
parent: unnamed-GtkWidgetAccessible-2
|
||||
state: enabled sensitive visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-4
|
||||
unnamed-GtkContainerAccessible-3
|
||||
"filler"
|
||||
parent: unnamed-GtkStackAccessible-2
|
||||
parent: unnamed-GtkStackAccessible-1
|
||||
index: 0
|
||||
state: enabled sensitive vertical visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-5
|
||||
unnamed-GtkContainerAccessible-4
|
||||
"filler"
|
||||
parent: unnamed-GtkContainerAccessible-4
|
||||
parent: unnamed-GtkContainerAccessible-3
|
||||
index: 0
|
||||
state: enabled sensitive vertical visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-6
|
||||
unnamed-GtkContainerAccessible-5
|
||||
"filler"
|
||||
parent: unnamed-GtkContainerAccessible-5
|
||||
parent: unnamed-GtkContainerAccessible-4
|
||||
index: 0
|
||||
state: enabled sensitive vertical visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-7
|
||||
unnamed-GtkContainerAccessible-6
|
||||
"filler"
|
||||
parent: unnamed-GtkContainerAccessible-6
|
||||
parent: unnamed-GtkContainerAccessible-5
|
||||
index: 0
|
||||
state: enabled sensitive vertical visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
unnamed-GtkButtonAccessible-8
|
||||
unnamed-GtkButtonAccessible-7
|
||||
"push button"
|
||||
parent: unnamed-GtkContainerAccessible-7
|
||||
parent: unnamed-GtkContainerAccessible-6
|
||||
index: 0
|
||||
name: New
|
||||
state: enabled focusable sensitive visible
|
||||
|
@ -18,7 +18,7 @@ window1
|
||||
alpha: 1
|
||||
<AtkValue>
|
||||
minimum value: 0.000000
|
||||
maximum value: 58.000000
|
||||
maximum value: 59.000000
|
||||
current value: 25.000000
|
||||
label1
|
||||
"label"
|
||||
|
@ -7,14 +7,6 @@ window1
|
||||
<AtkComponent>
|
||||
layer: window
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-0
|
||||
"panel"
|
||||
parent: window1
|
||||
state: enabled sensitive showing visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
scale1
|
||||
"slider"
|
||||
parent: window1
|
||||
|
@ -7,14 +7,6 @@ window1
|
||||
<AtkComponent>
|
||||
layer: window
|
||||
alpha: 1
|
||||
unnamed-GtkContainerAccessible-0
|
||||
"panel"
|
||||
parent: window1
|
||||
state: enabled sensitive showing visible
|
||||
toolkit: gtk
|
||||
<AtkComponent>
|
||||
layer: widget
|
||||
alpha: 1
|
||||
box1
|
||||
"filler"
|
||||
parent: window1
|
||||
|
Loading…
Reference in New Issue
Block a user