GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit ee844c63 authored by Michael Natterer's avatar Michael Natterer 😴

app: GimpDeviceManager refactoring part two

- change gimp_devices_get_list() to gimp_devices_get_manager()
- remove gimp_devices_get_current()
- let GimpDeviceStatus connect to the manager's "notify::current-device"
  directly and remove device status updating code from gui.c
- cleanup in gimpdevices.c
parent 21a0e550
......@@ -34,6 +34,7 @@
#include "widgets/gimpcontrollerwheel.h"
#include "widgets/gimpdeviceinfo.h"
#include "widgets/gimpdeviceinfo-coords.h"
#include "widgets/gimpdevicemanager.h"
#include "widgets/gimpdevices.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpuimanager.h"
......@@ -488,13 +489,16 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
(gimp_tool_control_get_motion_mode (active_tool->control) !=
GIMP_MOTION_MODE_EXACT)))
{
GdkDisplay *gdk_display = gtk_widget_get_display (canvas);
GdkDisplay *gdk_display = gtk_widget_get_display (canvas);
GimpDeviceManager *manager;
manager = gimp_devices_get_manager (gimp);
/* don't request motion hins for XInput devices because
* the wacom driver is known to report crappy hints
* (#6901) --mitch
*/
if (gimp_devices_get_current (gimp)->device ==
if (gimp_device_manager_get_current_device (manager)->device ==
gdk_display_get_core_pointer (gdk_display))
{
event_mask |= GDK_POINTER_MOTION_HINT_MASK;
......@@ -1393,9 +1397,12 @@ gimp_display_shell_proximity_out (GimpDisplayShell *shell)
static void
gimp_display_shell_check_device_cursor (GimpDisplayShell *shell)
{
GimpDeviceInfo *current_device;
GimpDeviceManager *manager;
GimpDeviceInfo *current_device;
manager = gimp_devices_get_manager (shell->display->gimp);
current_device = gimp_devices_get_current (shell->display->gimp);
current_device = gimp_device_manager_get_current_device (manager);
shell->draw_cursor = ! gimp_device_info_has_cursor (current_device);
}
......@@ -1460,7 +1467,9 @@ gimp_display_shell_space_pressed (GimpDisplayShell *shell,
case GIMP_SPACE_BAR_ACTION_PAN:
{
GimpCoords coords;
GimpDeviceManager *manager;
GimpDeviceInfo *current_device;
GimpCoords coords;
if (! gimp_display_shell_pointer_grab (shell, event,
GDK_POINTER_MOTION_MASK |
......@@ -1470,7 +1479,10 @@ gimp_display_shell_space_pressed (GimpDisplayShell *shell,
return;
}
gimp_device_info_get_device_coords (gimp_devices_get_current (gimp),
manager = gimp_devices_get_manager (gimp);
current_device = gimp_device_manager_get_current_device (manager);
gimp_device_info_get_device_coords (current_device,
gtk_widget_get_window (shell->canvas),
&coords);
......@@ -1631,14 +1643,19 @@ gimp_display_shell_get_event_coords (GimpDisplayShell *shell,
GdkModifierType *state,
guint32 *time)
{
Gimp *gimp = gimp_display_get_gimp (shell->display);
Gimp *gimp = gimp_display_get_gimp (shell->display);
GimpDeviceManager *manager;
GimpDeviceInfo *current_device;
manager = gimp_devices_get_manager (gimp);
current_device = gimp_device_manager_get_current_device (manager);
gimp_device_info_get_event_coords (gimp_devices_get_current (gimp),
gimp_device_info_get_event_coords (current_device,
gtk_widget_get_window (shell->canvas),
event,
display_coords);
gimp_device_info_get_event_state (gimp_devices_get_current (gimp),
gimp_device_info_get_event_state (current_device,
gtk_widget_get_window (shell->canvas),
event,
state);
......
......@@ -50,7 +50,6 @@
#include "widgets/gimpcolorselectorpalette.h"
#include "widgets/gimpcontrollers.h"
#include "widgets/gimpdevices.h"
#include "widgets/gimpdevicestatus.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpdnd.h"
#include "widgets/gimprender.h"
......@@ -120,9 +119,6 @@ static void gui_single_window_mode_notify (GimpGuiConfig *gui_config,
static void gui_tearoff_menus_notify (GimpGuiConfig *gui_config,
GParamSpec *pspec,
GtkUIManager *manager);
static void gui_device_change_notify (GimpDeviceManager *manager,
const GParamSpec *pspec,
Gimp *gimp);
static void gui_global_buffer_changed (Gimp *gimp);
......@@ -415,11 +411,6 @@ gui_restore_callback (Gimp *gimp,
NULL);
gimp_devices_init (gimp);
g_signal_connect (gimp_devices_get_list (gimp), "notify::current-device",
G_CALLBACK (gui_device_change_notify),
gimp);
gimp_controllers_init (gimp);
session_init (gimp);
......@@ -635,11 +626,6 @@ gui_exit_after_callback (Gimp *gimp,
gimp_render_exit (gimp);
gimp_controllers_exit (gimp);
g_signal_handlers_disconnect_by_func (gimp_devices_get_list (gimp),
gui_device_change_notify,
gimp);
gimp_devices_exit (gimp);
dialogs_exit (gimp);
......@@ -699,26 +685,6 @@ gui_tearoff_menus_notify (GimpGuiConfig *gui_config,
gtk_ui_manager_set_add_tearoffs (manager, gui_config->tearoff_menus);
}
static void
gui_device_change_notify (GimpDeviceManager *manager,
const GParamSpec *pspec,
Gimp *gimp)
{
GimpSessionInfo *session_info;
session_info = gimp_dialog_factory_find_session_info (gimp_dialog_factory_get_singleton (),
"gimp-device-status");
if (session_info && gimp_session_info_get_widget (session_info))
{
GtkWidget *device_status;
device_status = gtk_bin_get_child (GTK_BIN (gimp_session_info_get_widget (session_info)));
gimp_device_status_update (GIMP_DEVICE_STATUS (device_status));
}
}
static void
gui_global_buffer_changed (Gimp *gimp)
{
......
......@@ -36,6 +36,7 @@
#include "gimpdeviceeditor.h"
#include "gimpdeviceinfo.h"
#include "gimpdeviceinfoeditor.h"
#include "gimpdevicemanager.h"
#include "gimpdevices.h"
#include "gimpmessagebox.h"
#include "gimpmessagedialog.h"
......@@ -221,7 +222,7 @@ gimp_device_editor_constructed (GObject *object)
g_assert (GIMP_IS_GIMP (private->gimp));
devices = gimp_devices_get_list (private->gimp);
devices = GIMP_CONTAINER (gimp_devices_get_manager (private->gimp));
/* connect to "remove" before the container view does so we can get
* the notebook child stored in its model
......@@ -257,7 +258,9 @@ static void
gimp_device_editor_dispose (GObject *object)
{
GimpDeviceEditorPrivate *private = GIMP_DEVICE_EDITOR_GET_PRIVATE (object);
GimpContainer *devices = gimp_devices_get_list (private->gimp);
GimpContainer *devices;
devices = GIMP_CONTAINER (gimp_devices_get_manager (private->gimp));
g_signal_handlers_disconnect_by_func (devices,
gimp_device_editor_add_device,
......@@ -473,7 +476,7 @@ gimp_device_editor_delete_response (GtkWidget *dialog,
{
GimpContainer *devices;
devices = gimp_devices_get_list (private->gimp);
devices = GIMP_CONTAINER (gimp_devices_get_manager (private->gimp));
gimp_container_remove (devices, selected->data);
......
......@@ -55,11 +55,6 @@
#define GIMP_DEVICE_MANAGER_DATA_KEY "gimp-device-manager"
/* local function prototypes */
static GimpDeviceManager * gimp_device_manager_get (Gimp *gimp);
static gboolean devicerc_deleted = FALSE;
......@@ -71,7 +66,10 @@ gimp_devices_init (Gimp *gimp)
GimpDeviceManager *manager;
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (gimp_device_manager_get (gimp) == NULL);
manager = g_object_get_data (G_OBJECT (gimp), GIMP_DEVICE_MANAGER_DATA_KEY);
g_return_if_fail (manager == NULL);
manager = gimp_device_manager_new (gimp);
......@@ -87,9 +85,9 @@ gimp_devices_exit (Gimp *gimp)
g_return_if_fail (GIMP_IS_GIMP (gimp));
manager = gimp_device_manager_get (gimp);
manager = gimp_devices_get_manager (gimp);
g_return_if_fail (manager != NULL);
g_return_if_fail (GIMP_IS_DEVICE_MANAGER (manager));
g_object_set_data (G_OBJECT (gimp), GIMP_DEVICE_MANAGER_DATA_KEY, NULL);
}
......@@ -99,15 +97,16 @@ gimp_devices_restore (Gimp *gimp)
{
GimpDeviceManager *manager;
GimpContext *user_context;
GimpDeviceInfo *current_device;
GList *list;
gchar *filename;
GError *error = NULL;
g_return_if_fail (GIMP_IS_GIMP (gimp));
manager = gimp_device_manager_get (gimp);
manager = gimp_devices_get_manager (gimp);
g_return_if_fail (manager != NULL);
g_return_if_fail (GIMP_IS_DEVICE_MANAGER (manager));
user_context = gimp_get_user_context (gimp);
......@@ -140,11 +139,11 @@ gimp_devices_restore (Gimp *gimp)
g_free (filename);
gimp_context_copy_properties (GIMP_CONTEXT (gimp_device_manager_get_current_device (manager)),
user_context,
current_device = gimp_device_manager_get_current_device (manager);
gimp_context_copy_properties (GIMP_CONTEXT (current_device), user_context,
GIMP_DEVICE_INFO_CONTEXT_MASK);
gimp_context_set_parent (GIMP_CONTEXT (gimp_device_manager_get_current_device (manager)),
user_context);
gimp_context_set_parent (GIMP_CONTEXT (current_device), user_context);
}
void
......@@ -157,9 +156,9 @@ gimp_devices_save (Gimp *gimp,
g_return_if_fail (GIMP_IS_GIMP (gimp));
manager = gimp_device_manager_get (gimp);
manager = gimp_devices_get_manager (gimp);
g_return_if_fail (manager != NULL);
g_return_if_fail (GIMP_IS_DEVICE_MANAGER (manager));
if (devicerc_deleted && ! always_save)
return;
......@@ -195,9 +194,9 @@ gimp_devices_clear (Gimp *gimp,
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
manager = gimp_device_manager_get (gimp);
manager = gimp_devices_get_manager (gimp);
g_return_val_if_fail (manager != NULL, FALSE);
g_return_val_if_fail (GIMP_IS_DEVICE_MANAGER (manager), FALSE);
filename = gimp_personal_rc_file ("devicerc");
......@@ -218,32 +217,18 @@ 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 GIMP_CONTAINER (manager);
}
GimpDeviceInfo *
gimp_devices_get_current (Gimp *gimp)
GimpDeviceManager *
gimp_devices_get_manager (Gimp *gimp)
{
GimpDeviceManager *manager;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
manager = gimp_device_manager_get (gimp);
manager = g_object_get_data (G_OBJECT (gimp), GIMP_DEVICE_MANAGER_DATA_KEY);
g_return_val_if_fail (manager != NULL, NULL);
g_return_val_if_fail (GIMP_IS_DEVICE_MANAGER (manager), NULL);
return gimp_device_manager_get_current_device (manager);
return manager;
}
void
......@@ -286,9 +271,9 @@ gimp_devices_check_change (Gimp *gimp,
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
manager = gimp_device_manager_get (gimp);
manager = gimp_devices_get_manager (gimp);
g_return_val_if_fail (manager != NULL, FALSE);
g_return_val_if_fail (GIMP_IS_DEVICE_MANAGER (manager), FALSE);
/* It is possible that the event was propagated from a widget that does not
want extension events and therefore always sends core pointer events.
......@@ -337,12 +322,3 @@ gimp_devices_check_change (Gimp *gimp,
return FALSE;
}
/* private functions */
static GimpDeviceManager *
gimp_device_manager_get (Gimp *gimp)
{
return g_object_get_data (G_OBJECT (gimp), GIMP_DEVICE_MANAGER_DATA_KEY);
}
......@@ -19,27 +19,26 @@
#define __GIMP_DEVICES_H__
void gimp_devices_init (Gimp *gimp);
void gimp_devices_exit (Gimp *gimp);
void gimp_devices_init (Gimp *gimp);
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);
GimpContainer * gimp_devices_get_list (Gimp *gimp);
GimpDeviceInfo * gimp_devices_get_current (Gimp *gimp);
GimpDeviceManager * gimp_devices_get_manager (Gimp *gimp);
void gimp_devices_add_widget (Gimp *gimp,
GtkWidget *widget);
void gimp_devices_add_widget (Gimp *gimp,
GtkWidget *widget);
gboolean gimp_devices_check_callback (GtkWidget *widget,
GdkEvent *event,
Gimp *gimp);
gboolean gimp_devices_check_change (Gimp *gimp,
GdkEvent *event);
gboolean gimp_devices_check_callback (GtkWidget *widget,
GdkEvent *event,
Gimp *gimp);
gboolean gimp_devices_check_change (Gimp *gimp,
GdkEvent *event);
#endif /* __GIMP_DEVICES_H__ */
......@@ -39,6 +39,7 @@
#include "gimpdnd.h"
#include "gimpdeviceinfo.h"
#include "gimpdevicemanager.h"
#include "gimpdevices.h"
#include "gimpdevicestatus.h"
#include "gimpdialogfactory.h"
......@@ -88,6 +89,9 @@ static void gimp_device_status_device_remove (GimpContainer *devices,
GimpDeviceInfo *device_info,
GimpDeviceStatus *status);
static void gimp_device_status_notify_device (GimpDeviceManager *manager,
const GParamSpec *pspec,
GimpDeviceStatus *status);
static void gimp_device_status_update_entry (GimpDeviceInfo *device_info,
GimpDeviceStatusEntry *entry);
static void gimp_device_status_save_clicked (GtkWidget *button,
......@@ -149,7 +153,7 @@ gimp_device_status_constructed (GObject *object)
g_assert (GIMP_IS_GIMP (status->gimp));
devices = gimp_devices_get_list (status->gimp);
devices = GIMP_CONTAINER (gimp_devices_get_manager (status->gimp));
for (list = GIMP_LIST (devices)->list; list; list = list->next)
gimp_device_status_device_add (devices, list->data, status);
......@@ -161,7 +165,11 @@ gimp_device_status_constructed (GObject *object)
G_CALLBACK (gimp_device_status_device_remove),
status, 0);
gimp_device_status_update (status);
g_signal_connect (devices, "notify::current-device",
G_CALLBACK (gimp_device_status_notify_device),
status);
gimp_device_status_notify_device (GIMP_DEVICE_MANAGER (devices), NULL, status);
}
static void
......@@ -186,6 +194,10 @@ gimp_device_status_dispose (GObject *object)
g_list_free (status->devices);
status->devices = NULL;
g_signal_handlers_disconnect_by_func (gimp_devices_get_manager (status->gimp),
gimp_device_status_notify_device,
status);
}
G_OBJECT_CLASS (parent_class)->dispose (object);
......@@ -204,6 +216,7 @@ gimp_device_status_set_property (GObject *object,
case PROP_GIMP:
status->gimp = g_value_get_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -389,14 +402,17 @@ gimp_device_status_new (Gimp *gimp)
NULL);
}
void
gimp_device_status_update (GimpDeviceStatus *status)
/* private functions */
static void
gimp_device_status_notify_device (GimpDeviceManager *manager,
const GParamSpec *pspec,
GimpDeviceStatus *status)
{
GList *list;
g_return_if_fail (GIMP_IS_DEVICE_STATUS (status));
status->current_device = gimp_devices_get_current (status->gimp);
status->current_device = gimp_device_manager_get_current_device (manager);
for (list = status->devices; list; list = list->next)
{
......@@ -407,9 +423,6 @@ gimp_device_status_update (GimpDeviceStatus *status)
}
}
/* private functions */
static void
gimp_device_status_update_entry (GimpDeviceInfo *device_info,
GimpDeviceStatusEntry *entry)
......
......@@ -59,8 +59,7 @@ struct _GimpDeviceStatusClass
GType gimp_device_status_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_device_status_new (Gimp *gimp);
void gimp_device_status_update (GimpDeviceStatus *status);
GtkWidget * gimp_device_status_new (Gimp *gimp);
#endif /* __GIMP_DEVICE_STATUS_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment