Fix 'dist' target in Makefile
[notion/jeffpc.git] / mod_xinerama / mod_xinerama.c
blob84e3e010d5482f408c1cd0a12ed1c03b756a5875
1 /*
2 * Notion xinerama module
3 * based on mod_xrandr by Ragnar Rova and Tuomo Valkonen
5 * by Thomas Themel <themel0r@wannabehacker.com>
7 * splitted to read and setup part callable by lua
8 * by Tomas Ebenlendr <ebik@ucw.cz>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License,or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not,write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <X11/Xlib.h>
28 #include <X11/extensions/Xinerama.h>
29 #include <ioncore/common.h>
30 #include <ioncore/global.h>
31 #include <ioncore/mplex.h>
32 #include <ioncore/group-ws.h>
33 #include <ioncore/sizepolicy.h>
34 #include <ioncore/../version.h>
35 #include "exports.h"
37 #ifdef MOD_XINERAMA_DEBUG
38 #include <stdio.h>
39 #endif
41 char mod_xinerama_ion_api_version[]=ION_API_VERSION;
43 /* {{{ the actual xinerama query */
44 static int xinerama_event_base;
45 static int xinerama_error_base;
46 static bool xinerama_ready = FALSE;
48 /*EXTL_DOC
49 * Queries the Xinerama extension for screen configuration.
51 * Example output: \{\{x=0,y=0,w=1024,h=768\},\{x=1024,y=0,w=1280,h=1024\}\}
53 EXTL_SAFE
54 EXTL_EXPORT
55 ExtlTab mod_xinerama_query_screens()
57 XineramaScreenInfo* sInfo;
58 int nRects,i;
59 if (xinerama_ready) {
60 ExtlTab ret = extl_create_table();
62 sInfo = XineramaQueryScreens(ioncore_g.dpy, &nRects);
64 if(!sInfo) return ret;
66 for(i = 0 ; i < nRects ; ++i) {
67 ExtlTab rect = extl_create_table();
68 extl_table_sets_i(rect,"x",sInfo[i].x_org);
69 extl_table_sets_i(rect,"y",sInfo[i].y_org);
70 extl_table_sets_i(rect,"w",sInfo[i].width);
71 extl_table_sets_i(rect,"h",sInfo[i].height);
72 extl_table_seti_t(ret,i+1,rect);
75 XFree(sInfo);
76 return ret;
78 return extl_table_none();
81 /*EXTL_DOC
82 * Queries Notion for screen location and dimensions.
84 * Example output: \{x=0,y=0,w=1024,h=768\}
86 EXTL_SAFE
87 EXTL_EXPORT
88 ExtlTab mod_xinerama_get_screen_dimensions(WScreen *screen)
90 ExtlTab rect = extl_create_table();
92 extl_table_sets_i(rect,"x",REGION_GEOM(screen).x);
93 extl_table_sets_i(rect,"y",REGION_GEOM(screen).y);
94 extl_table_sets_i(rect,"w",REGION_GEOM(screen).w);
95 extl_table_sets_i(rect,"h",REGION_GEOM(screen).h);
97 return rect;
100 /* }}} */
102 /* {{{ Controlling notion screens from lua */
105 * Updates WFitParams based on the lua parameters
107 * @param screen dimensions (x/y/w/h)
109 static void convert_parameters(ExtlTab screen, WFitParams *fp)
111 WRectangle *g = &(fp->g);
112 extl_table_gets_i(screen,"x",&(g->x));
113 extl_table_gets_i(screen,"y",&(g->y));
114 extl_table_gets_i(screen,"w",&(g->w));
115 extl_table_gets_i(screen,"h",&(g->h));
116 fp->mode=REGION_FIT_EXACT;
117 fp->gravity=ForgetGravity;
120 /* Set up one new screen
121 * @param screen the screen to update
122 * @param dimensions the new dimensions (x/y/w/h)
124 EXTL_EXPORT
125 bool mod_xinerama_update_screen(WScreen *screen, ExtlTab dimensions)
127 WFitParams fp;
129 convert_parameters(dimensions, &fp);
131 #ifdef MOD_XINERAMA_DEBUG
132 printf("Updating rectangle #%d: x=%d y=%d width=%u height=%u\n",
133 screen->id, fp.g.x, fp.g.y, fp.g.w, fp.g.h);
134 #endif
136 region_fitrep((WRegion*)screen, NULL, &fp);
138 return TRUE;
141 /* Set up one new screen
142 * @param screen dimensions (x/y/w/h)
143 * @returns true on success, false on failure
145 EXTL_EXPORT
146 bool mod_xinerama_setup_new_screen(int screen_id, ExtlTab screen)
148 WRootWin* rootWin = ioncore_g.rootwins;
149 WScreen* newScreen;
150 WFitParams fp;
152 convert_parameters(screen, &fp);
154 newScreen = create_screen(rootWin, &fp, screen_id);
156 if(newScreen == NULL) {
157 warn(TR("Unable to create Xinerama workspace %d."), screen_id);
158 return FALSE;
161 region_set_manager((WRegion*)newScreen, (WRegion*)rootWin);
162 region_map((WRegion*)newScreen);
164 return mod_xinerama_update_screen(newScreen, screen);
167 /* }}} */
169 /* {{{ Module init and deinit */
170 bool mod_xinerama_init()
172 xinerama_ready = XineramaQueryExtension(ioncore_g.dpy,&xinerama_event_base, &xinerama_error_base);
173 if (!xinerama_ready)
174 warn(TR("No Xinerama support detected, mod_xinerama won't do anything."));
176 return mod_xinerama_register_exports();
180 void mod_xinerama_deinit()
182 mod_xinerama_unregister_exports();
184 /* }}} */