From: Mikko Rasa Date: Sat, 12 Dec 2015 16:21:48 +0000 (+0200) Subject: Implement a control interface using properties on the root window X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e2a0d9f8c960209bc03a24e04323603b3f231032;p=geometrycompositor.git Implement a control interface using properties on the root window --- diff --git a/.gitignore b/.gitignore index 0d0eef7..495a0ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /geometrycompositor +/geometrycontrol diff --git a/Makefile b/Makefile index 5f0dc21..43c845f 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,7 @@ +all: geometrycompositor geometrycontrol + geometrycompositor: source/main.c gcc -o $@ $< -Wall -Wextra -Werror -std=c90 -pedantic -ggdb -lm -lX11 -lXcomposite -lXdamage -lXext -lXrandr -lGL + +geometrycontrol: source/control.c + gcc -o $@ $< -Wall -Wextra -Werror -std=c90 -pedantic -ggdb -lX11 diff --git a/source/control.c b/source/control.c new file mode 100644 index 0000000..ae47c9e --- /dev/null +++ b/source/control.c @@ -0,0 +1,172 @@ +#include +#include +#include +#include +#include + +typedef struct GeometryCorrection +{ + char *monitor_name; + float keystone_vertical; + float cylinder_depth; + float vertical_center; + float perspective; +} GeometryCorrection; + +GeometryCorrection *get_corrections(Display *display) +{ + Window root; + Atom monitors_atom; + Atom correction_atom; + Atom prop_type; + int prop_format; + unsigned long overflow; + unsigned long names_length; + char *names; + unsigned long values_length; + short *values; + unsigned ncorrections; + unsigned i; + GeometryCorrection *corrections; + char *name_ptr; + + root = DefaultRootWindow(display); + monitors_atom = XInternAtom(display, "GEOMETRY_CORRECTION_MONITORS", False); + correction_atom = XInternAtom(display, "GEOMETRY_CORRECTION", False); + + XGetWindowProperty(display, root, monitors_atom, 0, 64, False, XA_STRING, + &prop_type, &prop_format, &names_length, &overflow, (unsigned char **)&names); + if(prop_type!=XA_STRING || prop_format!=8) + return NULL; + + XGetWindowProperty(display, root, correction_atom, 0, 64, False, XA_INTEGER, + &prop_type, &prop_format, &values_length, &overflow, (unsigned char **)&values); + if(prop_type!=XA_INTEGER || prop_format!=16) + { + XFree(names); + return NULL; + } + + ncorrections = 0; + for(i=0; ivalues_length) + ncorrections = values_length/4; + corrections = (GeometryCorrection *)malloc((ncorrections+1)*sizeof(GeometryCorrection)); + + name_ptr = names; + for(i=0; i \n", argv[0]); + return 1; + } + + display = XOpenDisplay(NULL); + + corrections = get_corrections(display); + if(corrections) + { + for(i=0; corrections[i].monitor_name; ++i) + if(!strcmp(corrections[i].monitor_name, argv[1])) + break; + } + else + i = 0; + + if(!corrections || !corrections[i].monitor_name) + { + unsigned namelen; + + corrections = (GeometryCorrection *)realloc(corrections, (i+2)*sizeof(GeometryCorrection)); + namelen = strlen(argv[1]); + corrections[i].monitor_name = (char *)malloc(namelen+1); + strcpy(corrections[i].monitor_name, argv[1]); + corrections[i+1].monitor_name = NULL; + } + + corrections[i].keystone_vertical = strtod(argv[2], NULL); + corrections[i].cylinder_depth = strtod(argv[3], NULL); + corrections[i].vertical_center = strtod(argv[4], NULL); + corrections[i].perspective = strtod(argv[5], NULL); + + set_corrections(display, corrections); + + XCloseDisplay(display); + + return 0; +} diff --git a/source/main.c b/source/main.c index 92537e2..1aee407 100644 --- a/source/main.c +++ b/source/main.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,7 @@ typedef struct CompositedWindow typedef struct CompositedMonitor { + char *name; int enabled; int x; int y; @@ -80,6 +82,8 @@ typedef struct Compositor PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB; PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT; PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT; + Atom correction_atom; + Atom monitors_atom; int dirty; } Compositor; @@ -533,6 +537,7 @@ int initialize_monitor(Compositor *compositor, CompositedScreen *screen, XRRScre { CompositedMonitor *monitor; XRROutputInfo *output; + int namelen; XRRCrtcInfo *crtc; unsigned buffers[2]; unsigned stride; @@ -540,6 +545,9 @@ int initialize_monitor(Compositor *compositor, CompositedScreen *screen, XRRScre monitor = &screen->monitors[index]; output = XRRGetOutputInfo(compositor->display, xrr_res, xrr_res->outputs[index]); + namelen = strlen(output->name); + monitor->name = (char *)malloc(namelen+1); + strcpy(monitor->name, output->name); monitor->enabled = !!output->crtc; if(!monitor->enabled) { @@ -582,6 +590,70 @@ int initialize_monitor(Compositor *compositor, CompositedScreen *screen, XRRScre return 1; } +CompositedMonitor *find_monitor_by_name(CompositedScreen *screen, char *name) +{ + unsigned i; + + for(i=0; inmonitors; ++i) + if(!strcmp(screen->monitors[i].name, name)) + return &screen->monitors[i]; + + return NULL; +} + +void update_geometry_correction(Compositor *compositor, CompositedScreen *screen) +{ + Atom prop_type; + int prop_format; + unsigned long overflow; + unsigned long names_length; + char *names; + unsigned long values_length; + short *values; + char *name_ptr; + unsigned i; + + XGetWindowProperty(compositor->display, screen->root, compositor->monitors_atom, 0, 64, False, XA_STRING, + &prop_type, &prop_format, &names_length, &overflow, (unsigned char **)&names); + if(prop_type!=XA_STRING || prop_format!=8) + return; + + XGetWindowProperty(compositor->display, screen->root, compositor->correction_atom, 0, 64, False, XA_INTEGER, + &prop_type, &prop_format, &values_length, &overflow, (unsigned char **)&values); + if(prop_type!=XA_INTEGER || prop_format!=16) + { + XFree(names); + return; + } + + use_gl(compositor, screen); + + name_ptr = names; + for(i=0; i*4=names+names_length) + break; + + monitor = find_monitor_by_name(screen, name_ptr); + if(monitor) + { + monitor->keystone_vertical = values[i*4]/10000.0f; + monitor->cylinder_depth = values[i*4+1]/10000.0f; + monitor->vertical_center = values[i*4+2]/10000.0f; + monitor->perspective = values[i*4+3]/10000.0f; + + update_monitor_vertices(screen, monitor); + } + + name_ptr += strlen(name_ptr)+1; + } + + XFree(names); + XFree(values); +} + int initialize_screen(Compositor *compositor, unsigned number) { CompositedScreen *screen; @@ -606,7 +678,7 @@ int initialize_screen(Compositor *compositor, unsigned number) return with_error("GLX_EXT_texture_from_pixmap is required"); screen->root = RootWindow(compositor->display, screen->number); - XSelectInput(compositor->display, screen->root, SubstructureNotifyMask); + XSelectInput(compositor->display, screen->root, SubstructureNotifyMask|PropertyChangeMask); screen->overlay = XCompositeGetOverlayWindow(compositor->display, screen->root); XGetGeometry(compositor->display, screen->overlay, &dummy_root, &x, &y, &screen->width, &screen->height, &border, &depth); XShapeCombineRectangles(compositor->display, screen->overlay, ShapeInput, 0, 0, NULL, 0, ShapeSet, Unsorted); @@ -625,6 +697,8 @@ int initialize_screen(Compositor *compositor, unsigned number) return 0; XRRFreeScreenResources(xrr_res); + update_geometry_correction(compositor, screen); + XQueryTree(compositor->display, screen->root, &dummy_root, &dummy_parent, &children, &nchildren); screen->windows = (CompositedWindow *)malloc(nchildren*sizeof(CompositedWindow)); @@ -694,6 +768,9 @@ int initialize_compositor(Compositor *compositor) compositor->glXBindTexImageEXT = (PFNGLXBINDTEXIMAGEEXTPROC)glXGetProcAddress((unsigned char *)"glXBindTexImageEXT"); compositor->glXReleaseTexImageEXT = (PFNGLXRELEASETEXIMAGEEXTPROC)glXGetProcAddress((unsigned char *)"glXReleaseTexImageEXT"); + compositor->correction_atom = XInternAtom(compositor->display, "GEOMETRY_CORRECTION", False); + compositor->monitors_atom = XInternAtom(compositor->display, "GEOMETRY_CORRECTION_MONITORS", False); + compositor->nscreens = ScreenCount(compositor->display); compositor->screens = (CompositedScreen *)malloc(compositor->nscreens*sizeof(CompositedScreen)); for(i=0; inscreens; ++i) @@ -723,12 +800,15 @@ void shutdown_screen(Compositor *compositor, CompositedScreen *screen) } for(i=0; inmonitors; ++i) + { + free(screen->monitors[i].name); if(screen->monitors[i].enabled) { glDeleteBuffers(1, &screen->monitors[i].vertex_buffer); glDeleteBuffers(1, &screen->monitors[i].index_buffer); glDeleteVertexArrays(1, &screen->monitors[i].vertex_array); } + } glDeleteBuffers(1, &screen->window_vertex_buffer); glDeleteVertexArrays(1, &screen->window_vertex_array); @@ -871,6 +951,20 @@ void process_configure_event(Compositor *compositor, XConfigureEvent *event) mark_dirty(compositor, screen); } +void process_property_event(Compositor *compositor, XPropertyEvent *event) +{ + CompositedScreen *screen; + + if(event->atom!=compositor->correction_atom) + return; + + screen = find_screen_by_root(compositor, event->window); + if(!screen) + return; + + update_geometry_correction(compositor, screen); +} + void process_damage_event(Compositor *compositor, XDamageNotifyEvent *event) { CompositedScreen *screen; @@ -916,6 +1010,9 @@ int process_event(Compositor *compositor) case ConfigureNotify: process_configure_event(compositor, &event.xconfigure); break; + case PropertyNotify: + process_property_event(compositor, &event.xproperty); + break; default: if(event.type==compositor->damage_event+XDamageNotify) process_damage_event(compositor, (XDamageNotifyEvent *)&event);