From a3de3e6ad1aae1f7bb2c718eebd1d635e6717916 Mon Sep 17 00:00:00 2001 From: Daniel Narvaez Date: Mon, 19 Nov 2012 15:54:24 +0000 Subject: Run xephyr in a custom window Xephyr doesn't work very well with multiple outputs. This should allow us to customize our behavior in that case. --- diff --git a/.gitignore b/.gitignore index 4e875a3..2bf3f44 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ logs/*.tar logs/all-logs.tar.bz2 commands/helpers/list-outputs commands/helpers/find-free-display +commands/helpers/xephyr-window prefs diff --git a/Makefile.helpers b/Makefile.helpers index 7bd2ad4..65b5138 100644 --- a/Makefile.helpers +++ b/Makefile.helpers @@ -1,17 +1,15 @@ HELPERS = $(COMMANDS)/helpers -XRANDR_LIBS = $(shell pkg-config --libs xrandr x11) -X11_LIBS = $(shell pkg-config --libs x11) +HELPERS_LIBS = $(shell pkg-config --libs xrandr x11) -$(HELPERS)/list-outputs: $(HELPERS)/list-outputs.c - gcc -o $(HELPERS)/list-outputs \ - $(HELPERS)/list-outputs.c $(XRANDR_LIBS) +$(HELPERS)/%: $(HELPERS)/%.c + gcc -o $@ $< $(HELPERS_LIBS) -$(HELPERS)/find-free-display: $(HELPERS)/find-free-display.c - gcc -o $(HELPERS)/find-free-display \ - $(HELPERS)/find-free-display.c $(X11_LIBS) +bin_HELPERS = $(HELPERS)/list-outputs \ + $(HELPERS)/find-free-display \ + $(HELPERS)/xephyr-window -helpers: $(HELPERS)/list-outputs $(HELPERS)/find-free-display +helpers: $(bin_HELPERS) clean-helpers: - rm -f $(HELPERS)/list-outputs $(HELPERS)/find-free-display + rm -f $(bin_HELPERS) diff --git a/commands/helpers/xephyr-window.c b/commands/helpers/xephyr-window.c new file mode 100755 index 0000000..b711f99 --- /dev/null +++ b/commands/helpers/xephyr-window.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + Display *display = XOpenDisplay(NULL); + Window window, root_window; + Atom atom; + int width = 100, height = 100; + + if (argc > 1) { + char *geometry = strdup(argv[1]); + char *delimiter = strchr(geometry, 'x'); + + if (delimiter == NULL) { + fprintf(stderr, "Cannot parse geometry\n"); + free(geometry); + exit(1); + } + + *delimiter = '\0'; + width = atoi(geometry); + height = atoi(delimiter + 1); + + free(geometry); + } + + root_window = RootWindow(display, 0); + + window = XCreateSimpleWindow(display, root_window, 0, 0, + width, height, 0, 0, 0); + + printf("%d\n", window); + fflush(stdout); + + if (argc < 2) { + atom = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", True); + XChangeProperty(display, window, + XInternAtom(display, "_NET_WM_STATE", True), + XA_ATOM, 32, PropModeReplace, + (unsigned char *)&atom, 1); + } + + XMapWindow(display, window); + + XFlush(display); + + while(1) { + sleep(60); + } + + XCloseDisplay(display); + + return(0); +} diff --git a/commands/run b/commands/run index 70f9611..875d2a7 100755 --- a/commands/run +++ b/commands/run @@ -32,13 +32,17 @@ else screen_dpi=`$helpersdir/get-screen-dpi` xephyr_options="-dpi $screen_dpi" - if [ -z $RUN_IN_WINDOW ]; then - xephyr_options="$xephyr_options -fullscreen" - fi + xidfile=`mktemp -t sugar-xephyr-xid-XXXXXX` + $helpersdir/xephyr-window $RESOLUTION > $xidfile & + xephyrwindowpid=$! - if [ ! -z $RESOLUTION ]; then - xephyr_options="$xephyr_options -screen $RESOLUTION" - fi + while [ ! -s $xidfile ] + do + sleep 1 + done + xephyr_options="$xephyr_options -parent `cat $xidfile`" xinit $helpersdir/xinitrc -- /usr/bin/Xephyr $display $xephyr_options + + kill $xephyrwindowpid fi -- cgit v0.9.1