Skip to content

Commit

Permalink
displaymanager: Handle list of displays in base class
Browse files Browse the repository at this point in the history
This moves the add/remove_display() functions from the subclasses to
GdkDisplay and GdkDisplayManager. It also gets rid of the list_displays
vfunc.
  • Loading branch information
Benjamin Otte committed Apr 15, 2013
1 parent d29a441 commit 7ef508f
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 161 deletions.
5 changes: 0 additions & 5 deletions gdk/broadway/gdkdisplay-broadway.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ G_DEFINE_TYPE (GdkBroadwayDisplay, gdk_broadway_display, GDK_TYPE_DISPLAY)
static void
gdk_broadway_display_init (GdkBroadwayDisplay *display)
{
_gdk_broadway_display_manager_add_display (gdk_display_manager_get (),
GDK_DISPLAY_OBJECT (display));
display->id_ht = g_hash_table_new (NULL, NULL);
}

Expand Down Expand Up @@ -239,9 +237,6 @@ gdk_broadway_display_dispose (GObject *object)
{
GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (object);

_gdk_broadway_display_manager_remove_display (gdk_display_manager_get (),
GDK_DISPLAY_OBJECT (object));

g_list_foreach (broadway_display->input_devices, (GFunc) g_object_run_dispose, NULL);

_gdk_screen_close (broadway_display->screens[0]);
Expand Down
40 changes: 0 additions & 40 deletions gdk/broadway/gdkdisplaymanager-broadway.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ struct _GdkBroadwayDisplayManager
{
GdkDisplayManager parent;

GSList *displays;

gboolean init_failed;
};

Expand Down Expand Up @@ -90,14 +88,6 @@ gdk_broadway_display_manager_open_display (GdkDisplayManager *manager,
return _gdk_broadway_display_open (name);
}

static GSList *
gdk_broadway_display_manager_list_displays (GdkDisplayManager *manager)
{
GdkBroadwayDisplayManager *manager_broadway = GDK_BROADWAY_DISPLAY_MANAGER (manager);

return g_slist_copy (manager_broadway->displays);
}

#include "../gdkkeynames.c"

static gchar *
Expand Down Expand Up @@ -137,38 +127,8 @@ gdk_broadway_display_manager_class_init (GdkBroadwayDisplayManagerClass *class)
object_class->finalize = gdk_broadway_display_manager_finalize;

manager_class->open_display = gdk_broadway_display_manager_open_display;
manager_class->list_displays = gdk_broadway_display_manager_list_displays;
manager_class->atom_intern = _gdk_broadway_display_manager_atom_intern;
manager_class->get_atom_name = _gdk_broadway_display_manager_get_atom_name;
manager_class->lookup_keyval = gdk_broadway_display_manager_lookup_keyval;
manager_class->get_keyval_name = gdk_broadway_display_manager_get_keyval_name;
}

void
_gdk_broadway_display_manager_add_display (GdkDisplayManager *manager,
GdkDisplay *display)
{
GdkBroadwayDisplayManager *manager_broadway = GDK_BROADWAY_DISPLAY_MANAGER (manager);

if (manager_broadway->displays == NULL)
gdk_display_manager_set_default_display (manager, display);

manager_broadway->displays = g_slist_prepend (manager_broadway->displays, display);
}

void
_gdk_broadway_display_manager_remove_display (GdkDisplayManager *manager,
GdkDisplay *display)
{
GdkBroadwayDisplayManager *manager_broadway = GDK_BROADWAY_DISPLAY_MANAGER (manager);

manager_broadway->displays = g_slist_remove (manager_broadway->displays, display);

if (gdk_display_manager_get_default_display (manager) == display)
{
if (manager_broadway->displays)
gdk_display_manager_set_default_display (manager, manager_broadway->displays->data);
else
gdk_display_manager_set_default_display (manager, NULL);
}
}
4 changes: 0 additions & 4 deletions gdk/broadway/gdkprivate-broadway.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ void _gdk_broadway_windowing_init (void);

gchar * _gdk_broadway_display_manager_get_atom_name (GdkDisplayManager *manager,
GdkAtom atom);
void _gdk_broadway_display_manager_add_display (GdkDisplayManager *manager,
GdkDisplay *display);
void _gdk_broadway_display_manager_remove_display (GdkDisplayManager *manager,
GdkDisplay *display);
GdkAtom _gdk_broadway_display_manager_atom_intern_static_string (GdkDisplayManager *manager,
const gchar *atom_name);
GdkAtom _gdk_broadway_display_manager_atom_intern (GdkDisplayManager *manager,
Expand Down
5 changes: 5 additions & 0 deletions gdk/gdkdisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "gdkdisplayprivate.h"

#include "gdkdeviceprivate.h"
#include "gdkdisplaymanagerprivate.h"
#include "gdkevents.h"
#include "gdkwindowimpl.h"
#include "gdkinternals.h"
Expand Down Expand Up @@ -206,6 +207,8 @@ gdk_display_init (GdkDisplay *display)

g_signal_connect (display, "opened",
G_CALLBACK (gdk_display_opened), NULL);

_gdk_display_manager_add_display (gdk_display_manager_get (), display);
}

static void
Expand All @@ -216,6 +219,8 @@ gdk_display_dispose (GObject *object)

device_manager = gdk_display_get_device_manager (GDK_DISPLAY (object));

_gdk_display_manager_remove_display (gdk_display_manager_get (), display);

g_list_free_full (display->queued_events, (GDestroyNotify) gdk_event_free);
display->queued_events = NULL;
display->queued_tail = NULL;
Expand Down
28 changes: 27 additions & 1 deletion gdk/gdkdisplaymanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ gdk_display_manager_set_default_display (GdkDisplayManager *manager,
GSList *
gdk_display_manager_list_displays (GdkDisplayManager *manager)
{
return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->list_displays (manager);
return g_slist_copy (manager->displays);
}

/**
Expand Down Expand Up @@ -589,3 +589,29 @@ gdk_atom_name (GdkAtom atom)

return GDK_DISPLAY_MANAGER_GET_CLASS (manager)->get_atom_name (manager, atom);
}

void
_gdk_display_manager_add_display (GdkDisplayManager *manager,
GdkDisplay *display)
{
if (manager->displays == NULL)
gdk_display_manager_set_default_display (manager, display);

manager->displays = g_slist_prepend (manager->displays, display);
}

/* NB: This function can be called multiple times per display. */
void
_gdk_display_manager_remove_display (GdkDisplayManager *manager,
GdkDisplay *display)
{
manager->displays = g_slist_remove (manager->displays, display);

if (manager->default_display == display)
{
if (manager->displays)
gdk_display_manager_set_default_display (manager, manager->displays->data);
else
gdk_display_manager_set_default_display (manager, NULL);
}
}
8 changes: 7 additions & 1 deletion gdk/gdkdisplaymanagerprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ struct _GdkDisplayManager
GObject parent_instance;

GdkDisplay *default_display;

GSList *displays;
};

struct _GdkDisplayManagerClass
{
GObjectClass parent_class;

GSList * (*list_displays) (GdkDisplayManager *manager);
GdkDisplay * (*open_display) (GdkDisplayManager *manager,
const gchar *name);

Expand All @@ -66,6 +67,11 @@ struct _GdkDisplayManagerClass
GdkDisplayManager *
_gdk_display_manager_get_nocreate (void);

void _gdk_display_manager_add_display (GdkDisplayManager *manager,
GdkDisplay *display);
void _gdk_display_manager_remove_display (GdkDisplayManager *manager,
GdkDisplay *display);

G_END_DECLS

#endif
5 changes: 0 additions & 5 deletions gdk/quartz/gdkdisplay-quartz.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,13 @@ G_DEFINE_TYPE (GdkQuartzDisplay, gdk_quartz_display, GDK_TYPE_DISPLAY)
static void
gdk_quartz_display_init (GdkQuartzDisplay *display)
{
_gdk_quartz_display_manager_add_display (gdk_display_manager_get (),
GDK_DISPLAY_OBJECT (display));
}

static void
gdk_quartz_display_dispose (GObject *object)
{
GdkQuartzDisplay *display_quartz = GDK_QUARTZ_DISPLAY (object);

_gdk_quartz_display_manager_remove_display (gdk_display_manager_get (),
GDK_DISPLAY_OBJECT (object));

g_list_foreach (display_quartz->input_devices,
(GFunc) g_object_run_dispose, NULL);

Expand Down
40 changes: 0 additions & 40 deletions gdk/quartz/gdkdisplaymanager-quartz.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
struct _GdkQuartzDisplayManager
{
GdkDisplayManager parent;

GSList *displays;
};


Expand All @@ -49,14 +47,6 @@ gdk_quartz_display_manager_open_display (GdkDisplayManager *manager,
return _gdk_quartz_display_open (name);
}

static GSList *
gdk_quartz_display_manager_list_displays (GdkDisplayManager *manager)
{
GdkQuartzDisplayManager *manager_quartz = GDK_QUARTZ_DISPLAY_MANAGER (manager);

return g_slist_copy (manager_quartz->displays);
}

#include "../gdkkeynames.c"

static gchar *
Expand Down Expand Up @@ -106,38 +96,8 @@ gdk_quartz_display_manager_class_init (GdkQuartzDisplayManagerClass *class)
object_class->finalize = gdk_quartz_display_manager_finalize;

manager_class->open_display = gdk_quartz_display_manager_open_display;
manager_class->list_displays = gdk_quartz_display_manager_list_displays;
manager_class->atom_intern = _gdk_quartz_display_manager_atom_intern;
manager_class->get_atom_name = _gdk_quartz_display_manager_get_atom_name;
manager_class->lookup_keyval = gdk_quartz_display_manager_lookup_keyval;
manager_class->get_keyval_name = gdk_quartz_display_manager_get_keyval_name;
}

void
_gdk_quartz_display_manager_add_display (GdkDisplayManager *manager,
GdkDisplay *display)
{
GdkQuartzDisplayManager *manager_quartz = GDK_QUARTZ_DISPLAY_MANAGER (manager);

if (manager_quartz->displays == NULL)
gdk_display_manager_set_default_display (manager, display);

manager_quartz->displays = g_slist_prepend (manager_quartz->displays, display);
}

void
_gdk_quartz_display_manager_remove_display (GdkDisplayManager *manager,
GdkDisplay *display)
{
GdkQuartzDisplayManager *manager_quartz = GDK_QUARTZ_DISPLAY_MANAGER (manager);

manager_quartz->displays = g_slist_remove (manager_quartz->displays, display);

if (gdk_display_manager_get_default_display (manager) == display)
{
if (manager_quartz->displays)
gdk_display_manager_set_default_display (manager, manager_quartz->displays->data);
else
gdk_display_manager_set_default_display (manager, NULL);
}
}
6 changes: 0 additions & 6 deletions gdk/quartz/gdkprivate-quartz.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ gchar * _gdk_quartz_display_utf8_to_string_target (GdkDisplay *disp
const gchar *str);


/* Display manager */
void _gdk_quartz_display_manager_add_display (GdkDisplayManager *manager,
GdkDisplay *display);
void _gdk_quartz_display_manager_remove_display (GdkDisplayManager *manager,
GdkDisplay *display);

/* Display manager methods - events */
GdkAtom _gdk_quartz_display_manager_atom_intern (GdkDisplayManager *manager,
const gchar *atom_name,
Expand Down
7 changes: 0 additions & 7 deletions gdk/wayland/gdkdisplaymanager-wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ gdk_wayland_display_manager_open_display (GdkDisplayManager *manager,
return _gdk_wayland_display_open (name);
}

static GSList *
gdk_wayland_display_manager_list_displays (GdkDisplayManager *manager)
{
return g_slist_copy (GDK_WAYLAND_DISPLAY_MANAGER (manager)->displays);
}

static GdkAtom
gdk_wayland_display_manager_atom_intern (GdkDisplayManager *manager_in,
const gchar *atom_name,
Expand Down Expand Up @@ -197,7 +191,6 @@ gdk_wayland_display_manager_class_init (GdkWaylandDisplayManagerClass *class)
object_class->finalize = gdk_wayland_display_manager_finalize;

manager_class->open_display = gdk_wayland_display_manager_open_display;
manager_class->list_displays = gdk_wayland_display_manager_list_displays;
manager_class->atom_intern = gdk_wayland_display_manager_atom_intern;
manager_class->get_atom_name = gdk_wayland_display_manager_get_atom_name;
manager_class->lookup_keyval = gdk_wayland_display_manager_lookup_keyval;
Expand Down
7 changes: 0 additions & 7 deletions gdk/win32/gdkdisplaymanager-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ gdk_win32_display_manager_open_display (GdkDisplayManager *manager,
return _gdk_win32_display_open (name);
}

static GSList *
gdk_win32_display_manager_list_displays (GdkDisplayManager *manager)
{
return g_slist_append (NULL, gdk_display_get_default ());
}

#include "../gdkkeynames.c"

static gchar *
Expand Down Expand Up @@ -96,7 +90,6 @@ gdk_win32_display_manager_class_init (GdkWin32DisplayManagerClass *class)
object_class->finalize = gdk_win32_display_manager_finalize;

manager_class->open_display = gdk_win32_display_manager_open_display;
manager_class->list_displays = gdk_win32_display_manager_list_displays;
manager_class->atom_intern = _gdk_win32_display_manager_atom_intern;
manager_class->get_atom_name = _gdk_win32_display_manager_get_atom_name;
manager_class->lookup_keyval = gdk_win32_display_manager_lookup_keyval;
Expand Down
5 changes: 0 additions & 5 deletions gdk/x11/gdkdisplay-x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ G_DEFINE_TYPE_WITH_CODE (GdkX11Display, gdk_x11_display, GDK_TYPE_DISPLAY,
static void
gdk_x11_display_init (GdkX11Display *display)
{
_gdk_x11_display_manager_add_display (gdk_display_manager_get (),
GDK_DISPLAY (display));
}

static void
Expand Down Expand Up @@ -1836,11 +1834,8 @@ gdk_x11_display_ungrab (GdkDisplay *display)
static void
gdk_x11_display_dispose (GObject *object)
{
GdkDisplay *display = GDK_DISPLAY (object);
GdkX11Display *display_x11 = GDK_X11_DISPLAY (object);

_gdk_x11_display_manager_remove_display (gdk_display_manager_get (), display);

g_list_foreach (display_x11->input_devices, (GFunc) g_object_run_dispose, NULL);

_gdk_screen_close (display_x11->screen);
Expand Down
Loading

0 comments on commit 7ef508f

Please sign in to comment.