From c36e4f5ae2822658ee667a8b7c6666d6ed79f884 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 29 Sep 2014 15:23:32 +0000 Subject: [PATCH] Add X11 Wayland interface This runs inside X11 using GTK+ and hosts Wayland clients. --- makefile | 9 +++ sys-xwl.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ util.h | 2 + 3 files changed, 177 insertions(+) create mode 100644 sys-xwl.c diff --git a/makefile b/makefile index bd3e1e7..385fb50 100644 --- a/makefile +++ b/makefile @@ -10,6 +10,15 @@ CFLAGS ?= -g -Wall PREFIX ?= /usr/local MANPREFIX ?= ${PREFIX}/share/man +ifeq ($(SYS),xwl) +GCC ?= gcc +PROG ?= wmpus +LDFLAGS += -lwayland-client -lwayland-server + +sys-xwl.o: CFLAGS += $(shell pkg-config --cflags gtk+-2.0) +wmpus: LDFLAGS += $(shell pkg-config --libs gtk+-2.0) +endif + ifeq ($(SYS),wl) GCC ?= gcc PROG ?= wmpus diff --git a/sys-xwl.c b/sys-xwl.c new file mode 100644 index 0000000..1bccf13 --- /dev/null +++ b/sys-xwl.c @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2014, Andy Spencer + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + */ + +#define _GNU_SOURCE +#include +#include +#include + +#include +#include +#include + +#include + +#include "util.h" +#include "conf.h" +#include "sys.h" +#include "wm.h" + +/* Internal structures */ +struct win_sys { + win_t *win; +}; + +/* Global data */ +static struct wl_display *display; +static struct wl_event_loop *events; + +/******************* + * Debug functions * + *******************/ +static const char * cmd_term[] = { "st-wl", NULL }; +static const char * cmd_menu[] = { "dmenu_run-wl", NULL }; + +static void cmd_exit(void *data, uint32_t time, uint32_t value, uint32_t state) +{ + if (state != WL_KEYBOARD_KEY_STATE_PRESSED) + return; + + printf("cmd_exit\n"); + exit(0); +} + +static void cmd_spawn(void *data, uint32_t time, uint32_t value, uint32_t state) +{ + char **cmd = data; + if (state != WL_KEYBOARD_KEY_STATE_PRESSED) + return; + + printf("cmd_spawn: %s\n", cmd[0]); + if (fork() == 0) { + execvp(cmd[0], cmd); + exit(0); + } +} + +/************* + * Callbacks * + *************/ + +static void new_window(void) +{ + printf("new_window\n"); +} + +static void new_screen(void) +{ + printf("new_screen\n"); +} + +/******************** + * System functions * + ********************/ +void sys_move(win_t *win, int x, int y, int w, int h) +{ + printf("sys_move: %p - %d,%d %dx%d\n", + win, x, y, w, h); +} + +void sys_raise(win_t *win) +{ + printf("sys_raise: %p\n", win); +} + +void sys_focus(win_t *win) +{ + printf("sys_focus: %p\n", win); +} + +void sys_show(win_t *win, state_t state) +{ + printf("sys_show: %p: %d", win, state); +} + +void sys_watch(win_t *win, event_t ev, mod_t mod) +{ + printf("sys_watch: %p - %x %hhx\n", + win, ev, mod2int(mod)); +} + +void sys_unwatch(win_t *win, event_t ev, mod_t mod) +{ + printf("sys_unwatch: %p - %x %hhx\n", + win, ev, mod2int(mod)); +} + +list_t *sys_info(win_t *win) +{ + printf("sys_info: %p\n", win); + return list_insert(NULL, win); +} + +win_t *sys_init(void) +{ + printf("sys_init\n"); + + /* Register log handler */ + wl_log_set_handler_server((wl_log_func_t)vprintf); + + /* Open the display */ + if (!(display = wl_display_create())) + error("Unable to create display"); + if (wl_display_add_socket(display, NULL) != 0) + error("Unable to add socket"); + if (!(events = wl_display_get_event_loop(display))) + error("Unable to get event loop"); + + /* Add input devices */ + (void)cmd_term; + (void)cmd_menu; + (void)cmd_exit; + (void)cmd_spawn; + (void)new_window; + (void)new_screen; + + return new0(win_t); +} + +void sys_run(win_t *root) +{ + printf("sys_run: %p\n", root); + wl_display_run(display); +} + +void sys_exit(void) +{ + printf("sys_exit\n"); + exit(0); +} + +void sys_free(win_t *root) +{ + printf("sys_free: %p\n", root); +} diff --git a/util.h b/util.h index 65b82f5..ccca871 100644 --- a/util.h +++ b/util.h @@ -16,8 +16,10 @@ /* Various utility functions */ /* Misc macros */ +#if !defined(MAX) && !defined(MIN) #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif #define new0(type) (calloc(1, sizeof(type))) -- 2.43.2