Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Benjamin Franzke |
Kristian Høgsberg | 05ad1e4 | 2013-09-17 14:41:03 -0700 | [diff] [blame] | 3 | * Copyright © 2013 Intel Corporation |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 4 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 5 | * 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 Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 12 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 13 | * 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 Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 25 | */ |
| 26 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 27 | #include "config.h" |
| 28 | |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 29 | #include "compositor.h" |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 30 | |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 31 | #include "launcher-util.h" |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 32 | #include "launcher-impl.h" |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 33 | |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 34 | #include <unistd.h> |
Bob Ham | 91880f1 | 2016-01-12 10:21:47 +0000 | [diff] [blame^] | 35 | #include <linux/input.h> |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 36 | |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 37 | static struct launcher_interface *ifaces[] = { |
| 38 | #ifdef HAVE_SYSTEMD_LOGIN |
| 39 | &launcher_logind_iface, |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 40 | #endif |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 41 | &launcher_weston_launch_iface, |
| 42 | &launcher_direct_iface, |
| 43 | NULL, |
Kristian Høgsberg | d2c9d8a | 2013-11-24 14:37:07 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 46 | WL_EXPORT struct weston_launcher * |
David Herrmann | cc5b2ed | 2013-10-22 00:28:09 +0200 | [diff] [blame] | 47 | weston_launcher_connect(struct weston_compositor *compositor, int tty, |
David Herrmann | 2ecb84a | 2014-12-30 14:33:22 +0100 | [diff] [blame] | 48 | const char *seat_id, bool sync_drm) |
Kristian Høgsberg | 05ad1e4 | 2013-09-17 14:41:03 -0700 | [diff] [blame] | 49 | { |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 50 | struct launcher_interface **it; |
Kristian Høgsberg | 05ad1e4 | 2013-09-17 14:41:03 -0700 | [diff] [blame] | 51 | |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 52 | for (it = ifaces; *it != NULL; it++) { |
| 53 | struct launcher_interface *iface = *it; |
| 54 | struct weston_launcher *launcher; |
Kristian Høgsberg | 05ad1e4 | 2013-09-17 14:41:03 -0700 | [diff] [blame] | 55 | |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 56 | if (iface->connect(&launcher, compositor, tty, seat_id, sync_drm) == 0) |
| 57 | return launcher; |
Kristian Høgsberg | 1eb482d | 2013-09-17 22:15:37 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 60 | return NULL; |
Kristian Høgsberg | 05ad1e4 | 2013-09-17 14:41:03 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 63 | WL_EXPORT void |
Kristian Høgsberg | 05ad1e4 | 2013-09-17 14:41:03 -0700 | [diff] [blame] | 64 | weston_launcher_destroy(struct weston_launcher *launcher) |
| 65 | { |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 66 | launcher->iface->destroy(launcher); |
| 67 | } |
Kristian Høgsberg | 3f49587 | 2013-09-18 23:00:17 -0700 | [diff] [blame] | 68 | |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 69 | WL_EXPORT int |
| 70 | weston_launcher_open(struct weston_launcher *launcher, |
| 71 | const char *path, int flags) |
| 72 | { |
| 73 | return launcher->iface->open(launcher, path, flags); |
| 74 | } |
David Herrmann | cc5b2ed | 2013-10-22 00:28:09 +0200 | [diff] [blame] | 75 | |
Jasper St. Pierre | 72dea06 | 2015-09-23 10:46:47 -0700 | [diff] [blame] | 76 | WL_EXPORT void |
| 77 | weston_launcher_close(struct weston_launcher *launcher, int fd) |
| 78 | { |
| 79 | launcher->iface->close(launcher, fd); |
| 80 | } |
| 81 | |
| 82 | WL_EXPORT int |
| 83 | weston_launcher_activate_vt(struct weston_launcher *launcher, int vt) |
| 84 | { |
| 85 | return launcher->iface->activate_vt(launcher, vt); |
| 86 | } |
| 87 | |
| 88 | WL_EXPORT void |
| 89 | weston_launcher_restore(struct weston_launcher *launcher) |
| 90 | { |
| 91 | launcher->iface->restore(launcher); |
Kristian Høgsberg | 05ad1e4 | 2013-09-17 14:41:03 -0700 | [diff] [blame] | 92 | } |
Bob Ham | 91880f1 | 2016-01-12 10:21:47 +0000 | [diff] [blame^] | 93 | |
| 94 | |
| 95 | static void |
| 96 | switch_vt_binding(struct weston_keyboard *keyboard, |
| 97 | uint32_t time, uint32_t key, void *data) |
| 98 | { |
| 99 | struct weston_compositor *compositor = data; |
| 100 | |
| 101 | weston_launcher_activate_vt(compositor->launcher, key - KEY_F1 + 1); |
| 102 | } |
| 103 | |
| 104 | WL_EXPORT void |
| 105 | weston_setup_vt_switch_bindings(struct weston_compositor *compositor) |
| 106 | { |
| 107 | uint32_t key; |
| 108 | |
| 109 | if (compositor->vt_switching == false) |
| 110 | return; |
| 111 | |
| 112 | for (key = KEY_F1; key < KEY_F9; key++) |
| 113 | weston_compositor_add_key_binding(compositor, key, |
| 114 | MODIFIER_CTRL | MODIFIER_ALT, |
| 115 | switch_vt_binding, |
| 116 | compositor); |
| 117 | } |