launcher-util.c 3.26 KB
Newer Older
Benjamin Franzke's avatar
Benjamin Franzke committed
1 2
/*
 * Copyright © 2012 Benjamin Franzke
3
 * Copyright © 2013 Intel Corporation
Benjamin Franzke's avatar
Benjamin Franzke committed
4
 *
5 6 7 8 9 10 11
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
Benjamin Franzke's avatar
Benjamin Franzke committed
12
 *
13 14 15 16 17 18 19 20 21 22 23 24
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
Benjamin Franzke's avatar
Benjamin Franzke committed
25 26
 */

27 28
#include "config.h"

29
#include <libweston/libweston.h>
30

Benjamin Franzke's avatar
Benjamin Franzke committed
31
#include "launcher-util.h"
32
#include "launcher-impl.h"
Benjamin Franzke's avatar
Benjamin Franzke committed
33

34
#include <stdint.h>
35
#include <unistd.h>
36
#include <linux/input.h>
37

38
static const struct launcher_interface *ifaces[] = {
39 40
#ifdef HAVE_SYSTEMD_LOGIN
	&launcher_logind_iface,
41
#endif
42 43 44 45
	&launcher_weston_launch_iface,
	&launcher_direct_iface,
	NULL,
};
46

47 48 49
WL_EXPORT struct weston_launcher *
weston_launcher_connect(struct weston_compositor *compositor, int tty,
			const char *seat_id, bool sync_drm)
50
{
51
	const struct launcher_interface **it;
52

53
	for (it = ifaces; *it != NULL; it++) {
54
		const struct launcher_interface *iface = *it;
55
		struct weston_launcher *launcher;
56

57 58 59
		if (iface->connect(&launcher, compositor, tty, seat_id, sync_drm) == 0)
			return launcher;
	}
60

61
	return NULL;
62 63
}

64 65
WL_EXPORT void
weston_launcher_destroy(struct weston_launcher *launcher)
66
{
67
	launcher->iface->destroy(launcher);
68 69
}

70
WL_EXPORT int
71
weston_launcher_open(struct weston_launcher *launcher,
Benjamin Franzke's avatar
Benjamin Franzke committed
72 73
		     const char *path, int flags)
{
74
	return launcher->iface->open(launcher, path, flags);
Benjamin Franzke's avatar
Benjamin Franzke committed
75 76
}

77
WL_EXPORT void
78 79
weston_launcher_close(struct weston_launcher *launcher, int fd)
{
80
	launcher->iface->close(launcher, fd);
81 82
}

83
WL_EXPORT int
84 85
weston_launcher_activate_vt(struct weston_launcher *launcher, int vt)
{
86
	return launcher->iface->activate_vt(launcher, vt);
87 88
}

89 90
static void
switch_vt_binding(struct weston_keyboard *keyboard,
91
		  const struct timespec *time, uint32_t key, void *data)
92 93
{
	struct weston_compositor *compositor = data;
94 95
	struct weston_launcher *launcher = compositor->launcher;
	int vt = key - KEY_F1 + 1;
96

97 98 99 100
	if (vt == launcher->iface->get_vt(launcher))
		return;

	weston_launcher_activate_vt(launcher, vt);
101 102 103 104 105 106
}

WL_EXPORT void
weston_setup_vt_switch_bindings(struct weston_compositor *compositor)
{
	uint32_t key;
107 108 109 110
	struct weston_launcher *launcher = compositor->launcher;

	if (launcher->iface->get_vt(launcher) <= 0)
		return;
111 112 113 114 115 116 117 118 119 120

	if (compositor->vt_switching == false)
		return;

	for (key = KEY_F1; key < KEY_F9; key++)
		weston_compositor_add_key_binding(compositor, key,
						  MODIFIER_CTRL | MODIFIER_ALT,
						  switch_vt_binding,
						  compositor);
}