blob: 2e472aedfe9d2f848803d9c4ed2e067ca0985867 [file] [log] [blame]
Benjamin Franzkebfeda132012-01-30 14:04:04 +01001/*
2 * Copyright © 2012 Benjamin Franzke
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -07003 * Copyright © 2013 Intel Corporation
Benjamin Franzkebfeda132012-01-30 14:04:04 +01004 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -07005 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
Benjamin Franzkebfeda132012-01-30 14:04:04 +010012 *
Bryce Harringtona0bbfea2015-06-11 15:35:43 -070013 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
Benjamin Franzkebfeda132012-01-30 14:04:04 +010025 */
26
Daniel Stonec228e232013-05-22 18:03:19 +030027#include "config.h"
28
Pekka Paalanen3d5d9472019-03-28 16:28:47 +020029#include <libweston/libweston.h>
Jasper St. Pierre72dea062015-09-23 10:46:47 -070030
Benjamin Franzkebfeda132012-01-30 14:04:04 +010031#include "launcher-util.h"
Jasper St. Pierre72dea062015-09-23 10:46:47 -070032#include "launcher-impl.h"
Benjamin Franzkebfeda132012-01-30 14:04:04 +010033
Jussi Kukkonen649bbce2016-07-19 14:16:27 +030034#include <stdint.h>
Jasper St. Pierre72dea062015-09-23 10:46:47 -070035#include <unistd.h>
Bob Ham91880f12016-01-12 10:21:47 +000036#include <linux/input.h>
Kristian Høgsberg3f495872013-09-18 23:00:17 -070037
Emil Velikov8f7201e2017-02-10 20:14:22 +000038static const struct launcher_interface *ifaces[] = {
Jasper St. Pierre72dea062015-09-23 10:46:47 -070039#ifdef HAVE_SYSTEMD_LOGIN
40 &launcher_logind_iface,
Kristian Høgsberg3f495872013-09-18 23:00:17 -070041#endif
Jasper St. Pierre72dea062015-09-23 10:46:47 -070042 &launcher_weston_launch_iface,
43 &launcher_direct_iface,
44 NULL,
Kristian Høgsbergd2c9d8a2013-11-24 14:37:07 -080045};
46
Jasper St. Pierre72dea062015-09-23 10:46:47 -070047WL_EXPORT struct weston_launcher *
David Herrmanncc5b2ed2013-10-22 00:28:09 +020048weston_launcher_connect(struct weston_compositor *compositor, int tty,
David Herrmann2ecb84a2014-12-30 14:33:22 +010049 const char *seat_id, bool sync_drm)
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -070050{
Emil Velikov8f7201e2017-02-10 20:14:22 +000051 const struct launcher_interface **it;
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -070052
Jasper St. Pierre72dea062015-09-23 10:46:47 -070053 for (it = ifaces; *it != NULL; it++) {
Emil Velikov8f7201e2017-02-10 20:14:22 +000054 const struct launcher_interface *iface = *it;
Jasper St. Pierre72dea062015-09-23 10:46:47 -070055 struct weston_launcher *launcher;
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -070056
Anurup Maa7de332020-12-03 07:55:04 +053057 weston_log("Trying %s launcher...\n", iface->name);
Jasper St. Pierre72dea062015-09-23 10:46:47 -070058 if (iface->connect(&launcher, compositor, tty, seat_id, sync_drm) == 0)
59 return launcher;
Kristian Høgsberg1eb482d2013-09-17 22:15:37 -070060 }
61
Jasper St. Pierre72dea062015-09-23 10:46:47 -070062 return NULL;
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -070063}
64
Jasper St. Pierre72dea062015-09-23 10:46:47 -070065WL_EXPORT void
Kristian Høgsberg05ad1e42013-09-17 14:41:03 -070066weston_launcher_destroy(struct weston_launcher *launcher)
67{
Jasper St. Pierre72dea062015-09-23 10:46:47 -070068 launcher->iface->destroy(launcher);
69}
Kristian Høgsberg3f495872013-09-18 23:00:17 -070070
Jasper St. Pierre72dea062015-09-23 10:46:47 -070071WL_EXPORT int
72weston_launcher_open(struct weston_launcher *launcher,
73 const char *path, int flags)
74{
75 return launcher->iface->open(launcher, path, flags);
76}
David Herrmanncc5b2ed2013-10-22 00:28:09 +020077
Jasper St. Pierre72dea062015-09-23 10:46:47 -070078WL_EXPORT void
79weston_launcher_close(struct weston_launcher *launcher, int fd)
80{
81 launcher->iface->close(launcher, fd);
82}
83
84WL_EXPORT int
85weston_launcher_activate_vt(struct weston_launcher *launcher, int vt)
86{
87 return launcher->iface->activate_vt(launcher, vt);
88}
89
Bob Ham91880f12016-01-12 10:21:47 +000090static void
91switch_vt_binding(struct weston_keyboard *keyboard,
Alexandros Frantzis47e79c82017-11-16 18:20:57 +020092 const struct timespec *time, uint32_t key, void *data)
Bob Ham91880f12016-01-12 10:21:47 +000093{
94 struct weston_compositor *compositor = data;
Giulio Camuffoa32986e2016-12-05 14:50:36 +010095 struct weston_launcher *launcher = compositor->launcher;
96 int vt = key - KEY_F1 + 1;
Bob Ham91880f12016-01-12 10:21:47 +000097
Giulio Camuffoa32986e2016-12-05 14:50:36 +010098 if (vt == launcher->iface->get_vt(launcher))
99 return;
100
101 weston_launcher_activate_vt(launcher, vt);
Bob Ham91880f12016-01-12 10:21:47 +0000102}
103
104WL_EXPORT void
105weston_setup_vt_switch_bindings(struct weston_compositor *compositor)
106{
107 uint32_t key;
nerdopolis68220db2018-06-29 08:17:48 -0400108 struct weston_launcher *launcher = compositor->launcher;
109
110 if (launcher->iface->get_vt(launcher) <= 0)
111 return;
Bob Ham91880f12016-01-12 10:21:47 +0000112
113 if (compositor->vt_switching == false)
114 return;
115
116 for (key = KEY_F1; key < KEY_F9; key++)
117 weston_compositor_add_key_binding(compositor, key,
118 MODIFIER_CTRL | MODIFIER_ALT,
119 switch_vt_binding,
120 compositor);
121}