2 * Copyright (c) 2014, Andy Spencer <andy753421@gmail.com>
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.
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
21 #include <xkbcommon/xkbcommon.h>
22 #include <wayland-server.h>
23 #include <wayland-client.h>
32 /* Internal structures */
38 static struct wl_display *display;
39 static struct wl_event_loop *events;
41 static GtkWidget *window;
47 static void on_destroy(GtkWidget *widget, GdkEvent *event, gpointer user_data)
49 printf("on_destroy\n");
53 static gboolean on_key(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
55 printf(g_ascii_isprint(event->keyval)
59 if (event->keyval == GDK_KEY_q)
61 if (event->keyval == GDK_KEY_t)
62 g_spawn_command_line_async("st-wl", NULL);
66 static gboolean on_button(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
68 printf("on_button\n");
72 static gboolean on_move(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
74 //printf("on_motion\n");
78 static gboolean on_wayland(gpointer user_data)
80 // TODO - convert to polled execution
81 wl_display_flush_clients(display);
82 wl_event_loop_dispatch(events, 0);
86 /*********************
88 *********************/
91 static void new_window(void)
93 printf("new_window\n");
96 static void new_screen(void)
98 printf("new_screen\n");
102 /***********************************
103 * Wayland Shared Memory Interface *
104 ***********************************/
106 struct wl_global *shm_ref;
108 static struct wl_shm_interface shm_iface = {
112 static void shm_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
114 printf("shm_bind\n");
116 struct wl_resource *res = wl_resource_create(client, &wl_shm_interface, version, id);
117 wl_resource_set_implementation(res, &shm_iface, NULL, NULL);
119 wl_shm_send_format(res, WL_SHM_FORMAT_XRGB8888);
120 wl_shm_send_format(res, WL_SHM_FORMAT_ARGB8888);
123 /********************
125 ********************/
126 void sys_move(win_t *win, int x, int y, int w, int h)
128 printf("sys_move: %p - %d,%d %dx%d\n",
132 void sys_raise(win_t *win)
134 printf("sys_raise: %p\n", win);
137 void sys_focus(win_t *win)
139 printf("sys_focus: %p\n", win);
142 void sys_show(win_t *win, state_t state)
144 printf("sys_show: %p: %d", win, state);
147 void sys_watch(win_t *win, event_t ev, mod_t mod)
149 printf("sys_watch: %p - %x %hhx\n",
150 win, ev, mod2int(mod));
153 void sys_unwatch(win_t *win, event_t ev, mod_t mod)
155 printf("sys_unwatch: %p - %x %hhx\n",
156 win, ev, mod2int(mod));
159 list_t *sys_info(win_t *win)
161 printf("sys_info: %p\n", win);
162 return list_insert(NULL, win);
165 win_t *sys_init(void)
167 printf("sys_init\n");
169 /* Register log handler */
170 wl_log_set_handler_server((wl_log_func_t)vprintf);
172 /* Open the display */
173 if (!(display = wl_display_create()))
174 error("Unable to create display");
175 if (wl_display_add_socket(display, NULL) != 0)
176 error("Unable to add socket");
177 if (!(events = wl_display_get_event_loop(display)))
178 error("Unable to get event loop");
180 /* Register interfaces */
181 shm_ref = wl_global_create(display, &wl_shm_interface, 1, NULL, &shm_bind);
183 /* Setup GTK display */
184 gtk_init(&conf_argc, &conf_argv);
185 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
186 gtk_widget_add_events(window,
188 GDK_BUTTON_PRESS_MASK |
189 GDK_BUTTON_RELEASE_MASK |
190 GDK_POINTER_MOTION_MASK);
191 g_signal_connect(window, "destroy", G_CALLBACK(on_destroy), NULL);
192 g_signal_connect(window, "key-press-event", G_CALLBACK(on_key), NULL);
193 g_signal_connect(window, "button-press-event", G_CALLBACK(on_button), NULL);
194 g_signal_connect(window, "motion-notify-event", G_CALLBACK(on_move), NULL);
195 g_timeout_add(1000/60, on_wayland, NULL);
196 gtk_widget_show(window);
201 void sys_run(win_t *root)
203 printf("sys_run: %p\n", root);
209 printf("sys_exit\n");
213 void sys_free(win_t *root)
215 printf("sys_free: %p\n", root);