]> Pileus Git - wmpus/blob - sys-wl.c
Cleanup a bit
[wmpus] / sys-wl.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 "util.h"
26 #include "conf.h"
27 #include "sys.h"
28 #include "wm.h"
29
30 /* Internal structures */
31 struct win_sys {
32         win_t *win;
33 };
34
35 /* Global data */
36 static struct wl_display    *display;
37 static struct wl_event_loop *events;
38
39 /*******************
40  * Debug functions *
41  *******************/
42 static const char * cmd_term[] = { "st-wl",        NULL };
43 static const char * cmd_menu[] = { "dmenu_run-wl", NULL };
44
45 static void cmd_exit(void *data, uint32_t time, uint32_t value, uint32_t state)
46 {
47         if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
48                 return;
49
50         printf("cmd_exit\n");
51         exit(0);
52 }
53
54 static void cmd_spawn(void *data, uint32_t time, uint32_t value, uint32_t state)
55 {
56         char **cmd = data;
57         if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
58                 return;
59
60         printf("cmd_spawn: %s\n", cmd[0]);
61         if (fork() == 0) {
62                 execvp(cmd[0], cmd);
63                 exit(0);
64         }
65 }
66
67 /*************
68  * Callbacks *
69  *************/
70
71 static void new_window(void)
72 {
73         printf("new_window\n");
74 }
75
76 static void new_screen(void)
77 {
78         printf("new_screen\n");
79 }
80
81 /********************
82  * System functions *
83  ********************/
84 void sys_move(win_t *win, int x, int y, int w, int h)
85 {
86         printf("sys_move: %p - %d,%d  %dx%d\n",
87                         win, x, y, w, h);
88 }
89
90 void sys_raise(win_t *win)
91 {
92         printf("sys_raise: %p\n", win);
93 }
94
95 void sys_focus(win_t *win)
96 {
97         printf("sys_focus: %p\n", win);
98 }
99
100 void sys_show(win_t *win, state_t state)
101 {
102         printf("sys_show: %p: %d", win, state);
103 }
104
105 void sys_watch(win_t *win, event_t ev, mod_t mod)
106 {
107         printf("sys_watch: %p - %x %hhx\n",
108                         win, ev, mod2int(mod));
109 }
110
111 void sys_unwatch(win_t *win, event_t ev, mod_t mod)
112 {
113         printf("sys_unwatch: %p - %x %hhx\n",
114                         win, ev, mod2int(mod));
115 }
116
117 list_t *sys_info(win_t *win)
118 {
119         printf("sys_info: %p\n", win);
120         return list_insert(NULL, win);
121 }
122
123 win_t *sys_init(void)
124 {
125         printf("sys_init\n");
126
127         /* Register log handler */
128         wl_log_set_handler_server((wl_log_func_t)vprintf);
129
130         /* Open the display */
131         if (!(display = wl_display_create()))
132                 error("Unable to  create display");
133         if (wl_display_add_socket(display, NULL) != 0)
134                 error("Unable to add socket");
135         if (!(events = wl_display_get_event_loop(display)))
136                 error("Unable to get event loop");
137
138         /* Add input devices */
139         (void)cmd_term;
140         (void)cmd_menu;
141         (void)cmd_exit;
142         (void)cmd_spawn;
143         (void)new_window;
144         (void)new_screen;
145
146         return new0(win_t);
147 }
148
149 void sys_run(win_t *root)
150 {
151         printf("sys_run: %p\n", root);
152         wl_display_run(display);
153 }
154
155 void sys_exit(void)
156 {
157         printf("sys_exit\n");
158         exit(0);
159 }
160
161 void sys_free(win_t *root)
162 {
163         printf("sys_free: %p\n", root);
164 }