2010-12-18 20:38:49 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
* gdkdisplaymanager-wayland.c
|
|
|
|
*
|
|
|
|
* Copyright 2010 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Author: Matthias clasen
|
|
|
|
*
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-18 20:38:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gdkdisplaymanagerprivate.h"
|
|
|
|
#include "gdkdisplay-wayland.h"
|
|
|
|
#include "gdkprivate-wayland.h"
|
2012-04-17 17:28:55 +00:00
|
|
|
#include "gdkwayland.h"
|
2010-12-18 20:38:49 +00:00
|
|
|
#include "gdkinternals.h"
|
|
|
|
|
2012-06-18 15:02:37 +00:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2011-01-07 19:21:56 +00:00
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
struct _GdkWaylandDisplayManager
|
|
|
|
{
|
|
|
|
GdkDisplayManager parent;
|
|
|
|
|
|
|
|
GSList *displays;
|
2011-12-13 17:39:43 +00:00
|
|
|
|
|
|
|
GHashTable *name_to_atoms;
|
|
|
|
guint next_atom;
|
2013-02-22 16:44:13 +00:00
|
|
|
|
|
|
|
gboolean init_failed;
|
2010-12-18 20:38:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GdkWaylandDisplayManagerClass
|
|
|
|
{
|
|
|
|
GdkDisplayManagerClass parent_class;
|
|
|
|
};
|
|
|
|
|
2013-02-22 16:44:13 +00:00
|
|
|
static void g_initable_iface_init (GInitableIface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GdkWaylandDisplayManager, gdk_wayland_display_manager, GDK_TYPE_DISPLAY_MANAGER,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, g_initable_iface_init))
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_wayland_display_manager_initable_init (GInitable *initable,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
struct wl_display *wl_display;
|
|
|
|
|
2013-04-12 17:39:20 +00:00
|
|
|
/* Set by the compositor when launching a special client - and it gets reset
|
|
|
|
* by wl_display_connect so we must avoid calling it twice
|
|
|
|
*/
|
|
|
|
if (g_getenv ("WAYLAND_SOCKET"))
|
|
|
|
return TRUE;
|
|
|
|
|
2013-02-22 16:44:13 +00:00
|
|
|
/* check that a connection to the default display is possible */
|
|
|
|
wl_display = wl_display_connect (gdk_get_display_arg_name ());
|
|
|
|
|
|
|
|
if (!wl_display)
|
|
|
|
{
|
|
|
|
GDK_WAYLAND_DISPLAY_MANAGER (initable)->init_failed = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_display_disconnect (wl_display);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_initable_iface_init (GInitableIface *iface)
|
|
|
|
{
|
|
|
|
iface->init = gdk_wayland_display_manager_initable_init;
|
|
|
|
}
|
2010-12-18 20:38:49 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_wayland_display_manager_finalize (GObject *object)
|
|
|
|
{
|
2013-02-22 16:44:13 +00:00
|
|
|
if (GDK_WAYLAND_DISPLAY_MANAGER (object)->init_failed == FALSE)
|
|
|
|
g_error ("A GdkWaylandDisplayManager object was finalized. This should not happen");
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
G_OBJECT_CLASS (gdk_wayland_display_manager_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkDisplay *
|
|
|
|
gdk_wayland_display_manager_open_display (GdkDisplayManager *manager,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
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 void
|
|
|
|
gdk_wayland_display_manager_set_default_display (GdkDisplayManager *manager,
|
|
|
|
GdkDisplay *display)
|
|
|
|
{
|
|
|
|
_gdk_wayland_display_make_default (display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkAtom
|
2011-12-13 17:39:43 +00:00
|
|
|
gdk_wayland_display_manager_atom_intern (GdkDisplayManager *manager_in,
|
2010-12-18 20:38:49 +00:00
|
|
|
const gchar *atom_name,
|
|
|
|
gboolean dup)
|
|
|
|
{
|
2011-12-13 17:39:43 +00:00
|
|
|
GdkWaylandDisplayManager *manager = GDK_WAYLAND_DISPLAY_MANAGER (manager_in);
|
|
|
|
GdkAtom atom;
|
|
|
|
gpointer data;
|
|
|
|
const gchar *atom_name_intern;
|
|
|
|
|
|
|
|
atom_name_intern = g_intern_string (atom_name);
|
|
|
|
data = g_hash_table_lookup (manager->name_to_atoms, atom_name_intern);
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
atom = GDK_POINTER_TO_ATOM (data);
|
|
|
|
return atom;
|
|
|
|
}
|
|
|
|
|
|
|
|
atom = _GDK_MAKE_ATOM (manager->next_atom);
|
|
|
|
|
|
|
|
g_hash_table_insert (manager->name_to_atoms,
|
|
|
|
(gchar *)atom_name_intern,
|
|
|
|
GDK_ATOM_TO_POINTER (atom));
|
|
|
|
manager->next_atom++;
|
|
|
|
|
|
|
|
return atom;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
2011-12-13 17:39:43 +00:00
|
|
|
gdk_wayland_display_manager_get_atom_name (GdkDisplayManager *manager_in,
|
2010-12-18 20:38:49 +00:00
|
|
|
GdkAtom atom)
|
|
|
|
{
|
2011-12-13 17:39:43 +00:00
|
|
|
GdkWaylandDisplayManager *manager = GDK_WAYLAND_DISPLAY_MANAGER (manager_in);
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, manager->name_to_atoms);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
|
|
|
{
|
2012-01-12 13:33:58 +00:00
|
|
|
if (GDK_POINTER_TO_ATOM (value) == atom)
|
|
|
|
return g_strdup (key);
|
2011-12-13 17:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
gdk_wayland_display_manager_lookup_keyval (GdkDisplayManager *manager,
|
|
|
|
const gchar *keyval_name)
|
|
|
|
{
|
2011-01-07 19:21:56 +00:00
|
|
|
g_return_val_if_fail (keyval_name != NULL, 0);
|
|
|
|
|
2012-10-26 00:52:30 +00:00
|
|
|
return xkb_keysym_from_name (keyval_name, 0);
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
gdk_wayland_display_manager_get_keyval_name (GdkDisplayManager *manager,
|
|
|
|
guint keyval)
|
|
|
|
{
|
2011-01-07 19:21:56 +00:00
|
|
|
static char buf[128];
|
|
|
|
|
|
|
|
switch (keyval)
|
|
|
|
{
|
2013-04-06 14:35:26 +00:00
|
|
|
case 0:
|
|
|
|
return NULL;
|
2011-01-07 19:21:56 +00:00
|
|
|
case GDK_KEY_Page_Up:
|
|
|
|
return "Page_Up";
|
|
|
|
case GDK_KEY_Page_Down:
|
|
|
|
return "Page_Down";
|
|
|
|
case GDK_KEY_KP_Page_Up:
|
|
|
|
return "KP_Page_Up";
|
|
|
|
case GDK_KEY_KP_Page_Down:
|
|
|
|
return "KP_Page_Down";
|
|
|
|
}
|
|
|
|
|
2012-07-11 13:43:50 +00:00
|
|
|
xkb_keysym_get_name(keyval, buf, sizeof (buf));
|
2011-01-07 19:21:56 +00:00
|
|
|
|
|
|
|
return buf;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_wayland_display_manager_class_init (GdkWaylandDisplayManagerClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
GdkDisplayManagerClass *manager_class = GDK_DISPLAY_MANAGER_CLASS (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->set_default_display = gdk_wayland_display_manager_set_default_display;
|
|
|
|
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;
|
|
|
|
manager_class->get_keyval_name = gdk_wayland_display_manager_get_keyval_name;
|
|
|
|
}
|
|
|
|
|
2012-03-16 21:45:51 +00:00
|
|
|
static struct {
|
2011-12-13 17:39:43 +00:00
|
|
|
const gchar *name;
|
|
|
|
guint atom_id;
|
|
|
|
} predefined_atoms[] = {
|
|
|
|
{ "NONE", 0 },
|
|
|
|
{ "PRIMARY", 1 },
|
|
|
|
{ "SECONDARY", 2 },
|
|
|
|
{ "ATOM", 4 },
|
|
|
|
{ "BITMAP", 5 },
|
|
|
|
{ "COLORMAP", 7 },
|
|
|
|
{ "DRAWABLE", 17 },
|
|
|
|
{ "INTEGER", 19 },
|
|
|
|
{ "PIXMAP", 20 },
|
|
|
|
{ "STRING", 31 },
|
|
|
|
{ "WINDOW", 33 },
|
|
|
|
{ "CLIPBOARD", 69 },
|
|
|
|
};
|
|
|
|
|
2010-12-18 20:38:49 +00:00
|
|
|
static void
|
|
|
|
gdk_wayland_display_manager_init (GdkWaylandDisplayManager *manager)
|
|
|
|
{
|
2011-12-13 17:39:43 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
manager->name_to_atoms = g_hash_table_new (NULL, NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (predefined_atoms); i++)
|
|
|
|
{
|
|
|
|
GdkAtom atom;
|
|
|
|
const gchar *atom_name = predefined_atoms[i].name;
|
|
|
|
|
|
|
|
atom = _GDK_MAKE_ATOM (predefined_atoms[i].atom_id);
|
|
|
|
g_hash_table_insert (manager->name_to_atoms,
|
|
|
|
(gchar *)g_intern_static_string (atom_name),
|
|
|
|
GDK_ATOM_TO_POINTER (atom));
|
|
|
|
}
|
|
|
|
|
|
|
|
manager->next_atom =
|
|
|
|
predefined_atoms[G_N_ELEMENTS (predefined_atoms) - 1].atom_id + 1;
|
2010-12-18 20:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gdk_wayland_display_manager_add_display (GdkDisplayManager *manager,
|
|
|
|
GdkDisplay *display)
|
|
|
|
{
|
|
|
|
GdkWaylandDisplayManager *manager_wayland = GDK_WAYLAND_DISPLAY_MANAGER (manager);
|
|
|
|
|
|
|
|
if (manager_wayland->displays == NULL)
|
|
|
|
gdk_display_manager_set_default_display (manager, display);
|
|
|
|
|
|
|
|
manager_wayland->displays = g_slist_prepend (manager_wayland->displays, display);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gdk_wayland_display_manager_remove_display (GdkDisplayManager *manager,
|
|
|
|
GdkDisplay *display)
|
|
|
|
{
|
|
|
|
GdkWaylandDisplayManager *manager_wayland = GDK_WAYLAND_DISPLAY_MANAGER (manager);
|
|
|
|
|
|
|
|
manager_wayland->displays = g_slist_remove (manager_wayland->displays, display);
|
|
|
|
|
2013-04-09 11:25:31 +00:00
|
|
|
if (gdk_display_manager_get_default_display (manager) == display)
|
2010-12-18 20:38:49 +00:00
|
|
|
{
|
|
|
|
if (manager_wayland->displays)
|
|
|
|
gdk_display_manager_set_default_display (manager, manager_wayland->displays->data);
|
|
|
|
else
|
|
|
|
gdk_display_manager_set_default_display (manager, NULL);
|
|
|
|
}
|
|
|
|
}
|