From 99577c8e88626dfae3d460b0df89d168f3f44624 Mon Sep 17 00:00:00 2001 From: ethereal Date: Wed, 25 Jan 2017 14:10:56 -0800 Subject: [PATCH] Change from using xdg shell v5 to v6. Also fix shell return value detection. --- Makefile | 8 +++--- config.mk | 2 +- st.c | 82 +++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 58 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 053d3e0..af0a6c4 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ include config.mk -SRC = st.c xdg-shell-unstable-v5-protocol.c +SRC = st.c xdg-shell-unstable-v6-protocol.c OBJ = ${SRC:.c=.o} all: options st @@ -17,15 +17,15 @@ options: config.h: cp config.def.h config.h -xdg-shell-unstable-v5-protocol.c: +xdg-shell-unstable-v6-protocol.c: @echo GEN $@ @wayland-scanner code ${XDG_SHELL_PROTO} $@ -xdg-shell-unstable-v5-client-protocol.h: +xdg-shell-unstable-v6-client-protocol.h: @echo GEN $@ @wayland-scanner client-header ${XDG_SHELL_PROTO} $@ -st.o: xdg-shell-unstable-v5-client-protocol.h +st.o: xdg-shell-unstable-v6-client-protocol.h .c.o: @echo CC $< diff --git a/config.mk b/config.mk index 7da06f1..61377c8 100644 --- a/config.mk +++ b/config.mk @@ -8,7 +8,7 @@ PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man PKGCFG = fontconfig wayland-client wayland-cursor xkbcommon wld -XDG_SHELL_PROTO = `pkg-config --variable=pkgdatadir wayland-protocols`/unstable/xdg-shell/xdg-shell-unstable-v5.xml +XDG_SHELL_PROTO = `pkg-config --variable=pkgdatadir wayland-protocols`/unstable/xdg-shell/xdg-shell-unstable-v6.xml # includes and libs INCS = -I. -I/usr/include `pkg-config --cflags ${PKGCFG}` diff --git a/st.c b/st.c index d3bcfd8..d905620 100644 --- a/st.c +++ b/st.c @@ -33,7 +33,7 @@ #include #include "arg.h" -#include "xdg-shell-unstable-v5-client-protocol.h" +#include "xdg-shell-unstable-v6-client-protocol.h" char *argv0; @@ -276,8 +276,9 @@ typedef struct { struct wl_data_offer *seloffer; struct wl_surface *surface; struct wl_buffer *buffer; - struct xdg_shell *shell; - struct xdg_surface *xdgsurface; + struct zxdg_shell_v6 *shell; + struct zxdg_surface_v6 *xdgsurface; + struct zxdg_toplevel_v6 *xdgtoplevel; XKB xkb; bool configured; int px, py; /* pointer x and y */ @@ -515,10 +516,12 @@ static void ptrbutton(void *, struct wl_pointer *, uint32_t, uint32_t, uint32_t, uint32_t); static void ptraxis(void *, struct wl_pointer *, uint32_t, uint32_t, wl_fixed_t); -static void xdgshellping(void *, struct xdg_shell *, uint32_t); -static void xdgsurfconfigure(void *, struct xdg_surface *, - int32_t, int32_t, struct wl_array *, uint32_t); -static void xdgsurfclose(void *, struct xdg_surface *); +static void xdgshellping(void *, struct zxdg_shell_v6 *, uint32_t); +static void xdgsurfconfigure(void *, struct zxdg_surface_v6 *, + uint32_t); +static void xdgtoplevelconfigure(void *, struct zxdg_toplevel_v6 *, + int32_t, int32_t, struct wl_array *); +static void xdgtoplevelclose(void *, struct zxdg_toplevel_v6 *); static void datadevoffer(void *, struct wl_data_device *, struct wl_data_offer *); static void datadeventer(void *, struct wl_data_device *, uint32_t, @@ -565,9 +568,11 @@ static struct wl_keyboard_listener kbdlistener = { kbdkeymap, kbdenter, kbdleave, kbdkey, kbdmodifiers, kbdrepeatinfo }; static struct wl_pointer_listener ptrlistener = { ptrenter, ptrleave, ptrmotion, ptrbutton, ptraxis }; -static struct xdg_shell_listener xdgshelllistener = { xdgshellping }; -static struct xdg_surface_listener xdgsurflistener = - { xdgsurfconfigure, xdgsurfclose }; +static struct zxdg_shell_v6_listener xdgshelllistener = { xdgshellping }; +static struct zxdg_surface_v6_listener xdgsurflistener = + { xdgsurfconfigure }; +static struct zxdg_toplevel_v6_listener xdgtoplevellistener = + { xdgtoplevelconfigure, xdgtoplevelclose }; static struct wl_data_device_listener datadevlistener = { datadevoffer, datadeventer, datadevleave, datadevmotion, datadevdrop, datadevselection }; @@ -1231,7 +1236,7 @@ sigchld(int a) return; if (!WIFEXITED(stat) || WEXITSTATUS(stat)) - die("child finished with error '%d'\n", stat); + die("child finished with error '%d'\n", WEXITSTATUS(stat)); exit(0); } @@ -3408,9 +3413,13 @@ wlinit(void) wl.surface = wl_compositor_create_surface(wl.cmp); wl_surface_add_listener(wl.surface, &surflistener, NULL); - wl.xdgsurface = xdg_shell_get_xdg_surface(wl.shell, wl.surface); - xdg_surface_add_listener(wl.xdgsurface, &xdgsurflistener, NULL); - xdg_surface_set_app_id(wl.xdgsurface, opt_class ? opt_class : termname); + wl.xdgsurface = zxdg_shell_v6_get_xdg_surface(wl.shell, wl.surface); + zxdg_surface_v6_add_listener(wl.xdgsurface, &xdgsurflistener, NULL); + wl.xdgtoplevel = zxdg_surface_v6_get_toplevel(wl.xdgsurface); + zxdg_toplevel_v6_set_app_id(wl.xdgtoplevel, + opt_class ? opt_class : termname); + zxdg_toplevel_v6_add_listener(wl.xdgtoplevel, &xdgtoplevellistener, + NULL); wl.xkb.ctx = xkb_context_new(0); wlresettitle(); @@ -3779,7 +3788,7 @@ wldrawcursor(void) void wlsettitle(char *title) { - xdg_surface_set_title(wl.xdgsurface, title); + zxdg_toplevel_v6_set_title(wl.xdgtoplevel, title); } void @@ -3945,12 +3954,10 @@ regglobal(void *data, struct wl_registry *registry, uint32_t name, if (strcmp(interface, "wl_compositor") == 0) { wl.cmp = wl_registry_bind(registry, name, &wl_compositor_interface, 3); - } else if (strcmp(interface, "xdg_shell") == 0) { + } else if (strcmp(interface, "zxdg_shell_v6") == 0) { wl.shell = wl_registry_bind(registry, name, - &xdg_shell_interface, 1); - xdg_shell_add_listener(wl.shell, &xdgshelllistener, NULL); - xdg_shell_use_unstable_version(wl.shell, - XDG_SHELL_VERSION_CURRENT); + &zxdg_shell_v6_interface, 1); + zxdg_shell_v6_add_listener(wl.shell, &xdgshelllistener, NULL); } else if (strcmp(interface, "wl_shm") == 0) { wl.shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); } else if (strcmp(interface, "wl_seat") == 0) { @@ -4293,27 +4300,44 @@ ptraxis(void * data, struct wl_pointer * pointer, uint32_t time, uint32_t axis, } void -xdgshellping(void *data, struct xdg_shell *shell, uint32_t serial) +xdgshellping(void *data, struct zxdg_shell_v6 *shell, uint32_t serial) { - xdg_shell_pong(shell, serial); + zxdg_shell_v6_pong(shell, serial); } void -xdgsurfconfigure(void *data, struct xdg_surface *surf, int32_t w, int32_t h, - struct wl_array *states, uint32_t serial) +xdgsurfconfigure(void *data, struct zxdg_surface_v6 *surf, uint32_t serial) { - xdg_surface_ack_configure(surf, serial); - if (w == wl.w && h == wl.h) + zxdg_surface_v6_ack_configure(surf, serial); +} + +void +xdgtoplevelconfigure(void *data, struct zxdg_toplevel_v6 *toplevel, + int32_t w, int32_t h, struct wl_array *states) +{ + + enum zxdg_toplevel_v6_state *state; + bool visible = 0; + wl_array_for_each(state, states) { + if(*state == ZXDG_TOPLEVEL_V6_STATE_ACTIVATED) visible = 1; + } + + if(visible) + wl.state |= WIN_VISIBLE; + else + wl.state &= ~WIN_VISIBLE; + + if(w == wl.w && h == wl.h) return; - cresize(w, h); - if (wl.configured) + cresize(w,h); + if(wl.configured) ttyresize(); else wl.configured = true; } void -xdgsurfclose(void *data, struct xdg_surface *surf) +xdgtoplevelclose(void *data, struct zxdg_toplevel_v6 *toplevel) { /* Send SIGHUP to shell */ kill(pid, SIGHUP);