]> Pileus Git - wmpus/blob - sys-xwl.c
Add X11 Wayland interface
[wmpus] / sys-xwl.c
1 /*
2  * Copyright (c) 2014, Andy Spencer <andy753421@gmail.com>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  */
15
16 #define _GNU_SOURCE
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20
21 #include <xkbcommon/xkbcommon.h>
22 #include <wayland-server.h>
23 #include <wayland-client.h>
24
25 #include <gtk/gtk.h>
26
27 #include "util.h"
28 #include "conf.h"
29 #include "sys.h"
30 #include "wm.h"
31
32 /* Internal structures */
33 struct win_sys {
34         win_t *win;
35 };
36
37 /* Global data */
38 static struct wl_display    *display;
39 static struct wl_event_loop *events;
40
41 /*******************
42  * Debug functions *
43  *******************/
44 static const char * cmd_term[] = { "st-wl",        NULL };
45 static const char * cmd_menu[] = { "dmenu_run-wl", NULL };
46
47 static void cmd_exit(void *data, uint32_t time, uint32_t value, uint32_t state)
48 {
49         if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
50                 return;
51
52         printf("cmd_exit\n");
53         exit(0);
54 }
55
56 static void cmd_spawn(void *data, uint32_t time, uint32_t value, uint32_t state)
57 {
58         char **cmd = data;
59         if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
60                 return;
61
62         printf("cmd_spawn: %s\n", cmd[0]);
63         if (fork() == 0) {
64                 execvp(cmd[0], cmd);
65                 exit(0);
66         }
67 }
68
69 /*************
70  * Callbacks *
71  *************/
72
73 static void new_window(void)
74 {
75         printf("new_window\n");
76 }
77
78 static void new_screen(void)
79 {
80         printf("new_screen\n");
81 }
82
83 /********************
84  * System functions *
85  ********************/
86 void sys_move(win_t *win, int x, int y, int w, int h)
87 {
88         printf("sys_move: %p - %d,%d  %dx%d\n",
89                         win, x, y, w, h);
90 }
91
92 void sys_raise(win_t *win)
93 {
94         printf("sys_raise: %p\n", win);
95 }
96
97 void sys_focus(win_t *win)
98 {
99         printf("sys_focus: %p\n", win);
100 }
101
102 void sys_show(win_t *win, state_t state)
103 {
104         printf("sys_show: %p: %d", win, state);
105 }
106
107 void sys_watch(win_t *win, event_t ev, mod_t mod)
108 {
109         printf("sys_watch: %p - %x %hhx\n",
110                         win, ev, mod2int(mod));
111 }
112
113 void sys_unwatch(win_t *win, event_t ev, mod_t mod)
114 {
115         printf("sys_unwatch: %p - %x %hhx\n",
116                         win, ev, mod2int(mod));
117 }
118
119 list_t *sys_info(win_t *win)
120 {
121         printf("sys_info: %p\n", win);
122         return list_insert(NULL, win);
123 }
124
125 win_t *sys_init(void)
126 {
127         printf("sys_init\n");
128
129         /* Register log handler */
130         wl_log_set_handler_server((wl_log_func_t)vprintf);
131
132         /* Open the display */
133         if (!(display = wl_display_create()))
134                 error("Unable to  create display");
135         if (wl_display_add_socket(display, NULL) != 0)
136                 error("Unable to add socket");
137         if (!(events = wl_display_get_event_loop(display)))
138                 error("Unable to get event loop");
139
140         /* Add input devices */
141         (void)cmd_term;
142         (void)cmd_menu;
143         (void)cmd_exit;
144         (void)cmd_spawn;
145         (void)new_window;
146         (void)new_screen;
147
148         return new0(win_t);
149 }
150
151 void sys_run(win_t *root)
152 {
153         printf("sys_run: %p\n", root);
154         wl_display_run(display);
155 }
156
157 void sys_exit(void)
158 {
159         printf("sys_exit\n");
160         exit(0);
161 }
162
163 void sys_free(win_t *root)
164 {
165         printf("sys_free: %p\n", root);
166 }