summaryrefslogtreecommitdiff
path: root/src/screen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/screen.c')
-rw-r--r--src/screen.c219
1 files changed, 215 insertions, 4 deletions
diff --git a/src/screen.c b/src/screen.c
index dec512a..f46e3ca 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -19,23 +19,27 @@
*/
#include "ratpoison.h"
+#include <string.h>
+#include <X11/cursorfont.h>
+
+static void init_screen (rp_screen *s, int screen_num);
int
screen_width (rp_screen *s)
{
- return DisplayWidth (dpy, s->screen_num) - defaults.padding_right - defaults.padding_left;
+ return s->width - defaults.padding_right - defaults.padding_left;
}
int
screen_height (rp_screen *s)
{
- return DisplayHeight (dpy, s->screen_num) - defaults.padding_bottom - defaults.padding_top;
+ return s->height - defaults.padding_bottom - defaults.padding_top;
}
int
screen_left (rp_screen *s)
{
- return defaults.padding_left;
+ return s->left + defaults.padding_left;
}
int
@@ -47,7 +51,7 @@ screen_right (rp_screen *s)
int
screen_top (rp_screen *s)
{
- return defaults.padding_top;
+ return s->top + defaults.padding_top;
}
int
@@ -116,3 +120,210 @@ screen_get_frame (rp_screen *s, int frame_num)
return NULL;
}
+
+/* Given a root window, return the rp_screen struct */
+rp_screen *
+find_screen (Window w)
+{
+ int i;
+
+ for (i=0; i<num_screens; i++)
+ if (screens[i].root == w) return &screens[i];
+
+ return NULL;
+ }
+
+void
+init_screens (int screen_arg, int screen_num)
+{
+ int i;
+
+ /* Get the number of screens */
+ if (rp_have_xinerama)
+ num_screens = xine_screen_count;
+ else
+ num_screens = ScreenCount (dpy);
+
+ /* make sure the screen specified is valid. */
+ if (screen_arg)
+ {
+ /* Using just a single Xinerama screen doesn't really make sense. So we
+ * disable Xinerama in this case.
+ */
+ if (rp_have_xinerama)
+ {
+ fprintf (stderr, "Warning: selecting a specific Xinerama screen is not implemented.\n");
+ rp_have_xinerama = 0;
+ screen_num = 0;
+ num_screens = ScreenCount(dpy);
+ }
+
+ if (screen_num < 0 || screen_num >= num_screens)
+ {
+ fprintf (stderr, "%d is an invalid screen for the display\n", screen_num);
+ exit (EXIT_FAILURE);
+ }
+
+ /* we're only going to use one screen. */
+ num_screens = 1;
+ }
+
+ /* Initialize the screens */
+ screens = (rp_screen *)xmalloc (sizeof (rp_screen) * num_screens);
+ PRINT_DEBUG (("%d screens.\n", num_screens));
+
+ if (screen_arg)
+ {
+ init_screen (&screens[0], screen_num);
+ }
+ else
+ {
+ for (i=0; i<num_screens; i++)
+ {
+ init_screen (&screens[i], i);
+ }
+ }
+
+}
+
+static void
+init_rat_cursor (rp_screen *s)
+{
+ s->rat = XCreateFontCursor( dpy, XC_icon );
+}
+
+static void
+init_screen (rp_screen *s, int screen_num)
+{
+ XGCValues gv;
+ int xine_screen_num;
+
+ /* We use screen_num below to refer to the real X screen number, but
+ * if we're using Xinerama, it will only be the Xinerama logical screen
+ * number. So we shuffle it away and replace it with the real one now,
+ * to cause confusion. -- CP
+ */
+ if (rp_have_xinerama)
+ {
+ xine_screen_num = screen_num;
+ screen_num = DefaultScreen(dpy);
+ xinerama_get_screen_info(xine_screen_num,
+ &s->left, &s->top, &s->width, &s->height);
+ }
+ else
+ {
+ xine_screen_num = screen_num;
+ s->left = 0;
+ s->top = 0;
+ s->width = DisplayWidth(dpy, screen_num);
+ s->height = DisplayHeight(dpy, screen_num);
+ }
+
+ /* Select on some events on the root window, if this fails, then
+ there is already a WM running and the X Error handler will catch
+ it, terminating ratpoison. */
+ XSelectInput(dpy, RootWindow (dpy, screen_num),
+ PropertyChangeMask | ColormapChangeMask
+ | SubstructureRedirectMask | SubstructureNotifyMask );
+ XSync (dpy, False);
+
+ /* Create the numset for the frames. */
+ s->frames_numset = numset_new ();
+
+ /* Build the display string for each screen */
+ s->display_string = xmalloc (strlen(DisplayString (dpy)) + 21);
+ sprintf (s->display_string, "DISPLAY=%s", DisplayString (dpy));
+ if (strrchr (DisplayString (dpy), ':'))
+ {
+ char *dot;
+
+ dot = strrchr(s->display_string, '.');
+ if (dot)
+ sprintf(dot, ".%i", screen_num);
+ }
+
+ PRINT_DEBUG (("%s\n", s->display_string));
+
+ s->screen_num = screen_num;
+ s->xine_screen_num = xine_screen_num;
+ s->root = RootWindow (dpy, screen_num);
+ s->def_cmap = DefaultColormap (dpy, screen_num);
+
+ init_rat_cursor (s);
+
+ s->fg_color = BlackPixel (dpy, s->screen_num);
+ s->bg_color = WhitePixel (dpy, s->screen_num);
+
+ /* Setup the GC for drawing the font. */
+ gv.foreground = s->fg_color;
+ gv.background = s->bg_color;
+ gv.function = GXcopy;
+ gv.line_width = 1;
+ gv.subwindow_mode = IncludeInferiors;
+ gv.font = defaults.font->fid;
+ s->normal_gc = XCreateGC(dpy, s->root,
+ GCForeground | GCBackground | GCFunction
+ | GCLineWidth | GCSubwindowMode | GCFont,
+ &gv);
+
+ /* Create the program bar window. */
+ s->bar_is_raised = 0;
+ s->bar_window = XCreateSimpleWindow (dpy, s->root, 0, 0, 1, 1,
+ defaults.bar_border_width,
+ s->fg_color, s->bg_color);
+
+ /* Setup the window that will receive all keystrokes once the prefix
+ key has been pressed. */
+ s->key_window = XCreateSimpleWindow (dpy, s->root, 0, 0, 1, 1, 0,
+ WhitePixel (dpy, s->screen_num),
+ BlackPixel (dpy, s->screen_num));
+ XSelectInput (dpy, s->key_window, KeyPressMask | KeyReleaseMask);
+ XMapWindow (dpy, s->key_window);
+
+ /* Create the input window. */
+ s->input_window = XCreateSimpleWindow (dpy, s->root, 0, 0, 1, 1,
+ defaults.bar_border_width,
+ s->fg_color, s->bg_color);
+ XSelectInput (dpy, s->input_window, KeyPressMask | KeyReleaseMask);
+
+ /* Create the frame indicator window */
+ s->frame_window = XCreateSimpleWindow (dpy, s->root, 1, 1, 1, 1, defaults.bar_border_width,
+ s->fg_color, s->bg_color);
+
+ /* Create the help window */
+ s->help_window = XCreateSimpleWindow (dpy, s->root, s->left, s->top, s->width,
+ s->height, 0, s->fg_color, s->bg_color);
+ XSelectInput (dpy, s->help_window, KeyPressMask);
+
+ XSync (dpy, 0);
+}
+
+static int
+is_rp_window_for_given_screen (Window w, rp_screen *s)
+{
+ if (w != s->key_window &&
+ w != s->bar_window &&
+ w != s->input_window &&
+ w != s->frame_window &&
+ w != s->help_window)
+ return 0;
+ return 1;
+}
+
+int
+is_rp_window_for_screen(Window w, rp_screen *s)
+{
+ int i;
+
+ if (rp_have_xinerama)
+ {
+ for (i=0; i<num_screens; i++)
+ if (is_rp_window_for_given_screen(w, &screens[i])) return 1;
+ return 0;
+ }
+ else
+ {
+ return is_rp_window_for_given_screen(w, s);
+ }
+}
+