Skip to content

Commit 4c4f70a

Browse files
committed
drm: Respect XDG_SEAT for libinput seat selection
Instead of hardcoding "seat0" for enumerating available inputs under the DRM platform, use the value optionally provided by the standard environment variable XDG_SEAT, or by the config file setting "seat", or by a command line setting "seat", and fall back to the previous default if unavailable. This allows running cog on a dedicated seat with its own display and input devices, while leaving the default seat0 available for other uses.
1 parent a6bd908 commit 4c4f70a

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

platform/drm/cog-platform-drm.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct _CogDrmPlatform {
6868
CogDrmRenderer *renderer;
6969
CogGLRendererRotation rotation;
7070
GList *rotatable_input_devices;
71+
char *seat_name;
7172
bool draw_cursor;
7273
bool dispatch_pointer;
7374
bool use_gles;
@@ -245,13 +246,26 @@ parse_bool(const char *value, bool *out)
245246
return false;
246247
}
247248

249+
static void
250+
set_seat_name(CogDrmPlatform *self, const char *seat_name)
251+
{
252+
g_free(self->seat_name);
253+
self->seat_name = g_strdup(seat_name);
254+
}
255+
248256
static void
249257
init_config(CogDrmPlatform *self, CogShell *shell, const char *params_string)
250258
{
251259
drm_data.device_scale = cog_shell_get_device_scale_factor (shell);
252260
g_debug ("init_config: overriding device_scale value, using %.2f from shell",
253261
drm_data.device_scale);
254262

263+
{
264+
const char *env_seat_name = g_getenv("XDG_SEAT");
265+
if (env_seat_name && *env_seat_name)
266+
set_seat_name(self, env_seat_name);
267+
}
268+
255269
self->draw_cursor = g_getenv("COG_PLATFORM_DRM_CURSOR") != NULL;
256270
self->dispatch_pointer = g_getenv("COG_PLATFORM_DRM_POINTER") != NULL;
257271

@@ -289,6 +303,12 @@ init_config(CogDrmPlatform *self, CogShell *shell, const char *params_string)
289303
g_warning("Invalid renderer '%s', using default.", value);
290304
}
291305

306+
{
307+
g_autofree char *value = g_key_file_get_string(key_file, "drm", "seat", NULL);
308+
if (value && *value)
309+
set_seat_name(self, value);
310+
}
311+
292312
{
293313
g_autoptr(GError) lookup_error = NULL;
294314
gboolean value = g_key_file_get_boolean(key_file, "drm", "cursor", &lookup_error);
@@ -331,6 +351,11 @@ init_config(CogDrmPlatform *self, CogShell *shell, const char *params_string)
331351
g_warning("Invalid value '%s' for parameter '%s'.", v, k);
332352
else
333353
self->rotation = val;
354+
} else if (g_strcmp0(k, "seat") == 0) {
355+
if (*v)
356+
set_seat_name(self, v);
357+
else
358+
g_warning("Invalid value '%s' for parameter '%s'.", v, k);
334359
} else if (g_strcmp0(k, "cursor") == 0) {
335360
if (!parse_bool(v, &self->draw_cursor))
336361
g_warning("Invalid value '%s' for parameter '%s'.", v, k);
@@ -1343,7 +1368,9 @@ init_input(CogDrmPlatform *platform)
13431368
input_data.rotation = platform->rotation;
13441369
input_data.dispatch_pointer = platform->dispatch_pointer;
13451370

1346-
int ret = libinput_udev_assign_seat (input_data.libinput, "seat0");
1371+
g_debug("init_input: assigning libinput to seat '%s'", platform->seat_name);
1372+
1373+
int ret = libinput_udev_assign_seat(input_data.libinput, platform->seat_name);
13471374
if (ret)
13481375
return FALSE;
13491376

@@ -1604,6 +1631,8 @@ cog_drm_platform_finalize(GObject *object)
16041631
clear_cursor();
16051632
clear_drm();
16061633

1634+
g_clear_pointer(&self->seat_name, g_free);
1635+
16071636
G_OBJECT_CLASS(cog_drm_platform_parent_class)->finalize(object);
16081637
}
16091638

@@ -1756,6 +1785,7 @@ cog_drm_platform_class_finalize(CogDrmPlatformClass *klass)
17561785
static void
17571786
cog_drm_platform_init(CogDrmPlatform *self)
17581787
{
1788+
set_seat_name(self, "seat0");
17591789
}
17601790

17611791
G_MODULE_EXPORT void

0 commit comments

Comments
 (0)