diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clickety.c | 30 | ||||
-rw-r--r-- | src/composite.c | 90 | ||||
-rw-r--r-- | src/context.c | 6 | ||||
-rw-r--r-- | src/desktop.c | 10 | ||||
-rw-r--r-- | src/key.c | 18 | ||||
-rw-r--r-- | src/logo.c | 12 | ||||
-rw-r--r-- | src/overlay.c | 208 | ||||
-rw-r--r-- | src/screen.c | 6 | ||||
-rw-r--r-- | src/vwm.c | 394 | ||||
-rw-r--r-- | src/vwm.h | 15 | ||||
-rw-r--r-- | src/window.c | 32 | ||||
-rw-r--r-- | src/xevent.c | 18 | ||||
-rw-r--r-- | src/xwindow.c | 30 |
13 files changed, 453 insertions, 416 deletions
diff --git a/src/clickety.c b/src/clickety.c index a64e6d7..edfa123 100644 --- a/src/clickety.c +++ b/src/clickety.c @@ -121,7 +121,7 @@ void vwm_clickety_motion(vwm_t *vwm, Window win, XMotionEvent *motion) case VWM_ADJUST_MOVE: changes.x = clickety.orig.x + (motion->x_root - clickety.impetus_x_root); changes.y = clickety.orig.y + (motion->y_root - clickety.impetus_y_root); - XConfigureWindow(vwm->display, win, CWX | CWY | CWBorderWidth, &changes); + XConfigureWindow(VWM_XDISPLAY(vwm), win, CWX | CWY | CWBorderWidth, &changes); break; case VWM_ADJUST_RESIZE: { @@ -132,9 +132,9 @@ void vwm_clickety_motion(vwm_t *vwm, Window win, XMotionEvent *motion) compute_resize((XEvent *)motion, &resized); /* TODO: this is probably broken with compositing active, but it doesn't seem to be too messed up in practice */ /* erase the last rectangle */ - XDrawRectangle(vwm->display, VWM_XROOT(vwm), vwm->gc, clickety.lastrect.x, clickety.lastrect.y, clickety.lastrect.width, clickety.lastrect.height); + XDrawRectangle(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), VWM_XGC(vwm), clickety.lastrect.x, clickety.lastrect.y, clickety.lastrect.width, clickety.lastrect.height); /* draw a frame @ resized coordinates */ - XDrawRectangle(vwm->display, VWM_XROOT(vwm), vwm->gc, resized.x, resized.y, resized.width, resized.height); + XDrawRectangle(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), VWM_XGC(vwm), resized.x, resized.y, resized.width, resized.height); /* remember the last rectangle */ clickety.lastrect = resized; break; @@ -156,20 +156,20 @@ void vwm_clickety_released(vwm_t *vwm, Window win, XButtonPressedEvent *terminus case VWM_ADJUST_MOVE: changes.x = clickety.orig.x + (terminus->x_root - clickety.impetus_x_root); changes.y = clickety.orig.y + (terminus->y_root - clickety.impetus_y_root); - XConfigureWindow(vwm->display, win, CWX | CWY | CWBorderWidth, &changes); + XConfigureWindow(VWM_XDISPLAY(vwm), win, CWX | CWY | CWBorderWidth, &changes); break; case VWM_ADJUST_RESIZE: { XWindowAttributes resized; compute_resize((XEvent *)terminus, &resized); /* move and resize the window @ resized */ - XDrawRectangle(vwm->display, VWM_XROOT(vwm), vwm->gc, clickety.lastrect.x, clickety.lastrect.y, clickety.lastrect.width, clickety.lastrect.height); + XDrawRectangle(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), VWM_XGC(vwm), clickety.lastrect.x, clickety.lastrect.y, clickety.lastrect.width, clickety.lastrect.height); changes.x = resized.x; changes.y = resized.y; changes.width = resized.width; changes.height = resized.height; - XConfigureWindow(vwm->display, win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &changes); - XUngrabServer(vwm->display); + XConfigureWindow(VWM_XDISPLAY(vwm), win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &changes); + XUngrabServer(VWM_XDISPLAY(vwm)); break; } @@ -181,8 +181,8 @@ void vwm_clickety_released(vwm_t *vwm, Window win, XButtonPressedEvent *terminus clickety.vwin = NULL; /* reset clickety */ - XFlush(vwm->display); - XUngrabPointer(vwm->display, CurrentTime); + XFlush(VWM_XDISPLAY(vwm)); + XUngrabPointer(VWM_XDISPLAY(vwm), CurrentTime); } @@ -192,7 +192,7 @@ int vwm_clickety_pressed(vwm_t *vwm, Window win, XButtonPressedEvent *impetus) vwm_window_t *vwin; /* verify the window still exists */ - if (!XGetWindowAttributes(vwm->display, win, &clickety.orig)) goto _fail; + if (!XGetWindowAttributes(VWM_XDISPLAY(vwm), win, &clickety.orig)) goto _fail; if (!(vwin = vwm_win_lookup(vwm, win))) goto _fail; @@ -210,16 +210,16 @@ int vwm_clickety_pressed(vwm_t *vwm, Window win, XButtonPressedEvent *impetus) /* immediately raise the window if we're relocating, * resizes are supported without raising (which also enables NULL resizes to focus without raising) */ clickety.mode = VWM_ADJUST_MOVE; - XRaiseWindow(vwm->display, win); + XRaiseWindow(VWM_XDISPLAY(vwm), win); break; case Button3: /* grab the server on resize for the xor rubber-banding's sake */ - XGrabServer(vwm->display); - XSync(vwm->display, False); + XGrabServer(VWM_XDISPLAY(vwm)); + XSync(VWM_XDISPLAY(vwm), False); /* FIXME: none of the resize DrawRectangle() calls consider the window border. */ - XDrawRectangle(vwm->display, VWM_XROOT(vwm), vwm->gc, clickety.orig.x, clickety.orig.y, clickety.orig.width, clickety.orig.height); + XDrawRectangle(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), VWM_XGC(vwm), clickety.orig.x, clickety.orig.y, clickety.orig.width, clickety.orig.height); clickety.lastrect = clickety.orig; clickety.mode = VWM_ADJUST_RESIZE; @@ -238,7 +238,7 @@ int vwm_clickety_pressed(vwm_t *vwm, Window win, XButtonPressedEvent *impetus) return 1; _fail: - XUngrabPointer(vwm->display, CurrentTime); + XUngrabPointer(VWM_XDISPLAY(vwm), CurrentTime); return 0; } diff --git a/src/composite.c b/src/composite.c index df157f6..79a001c 100644 --- a/src/composite.c +++ b/src/composite.c @@ -44,17 +44,17 @@ static int repaint_needed; /* bind the window to a "namewindowpixmap" and create a picture from it (compositing) */ static void bind_namewindow(vwm_t *vwm, vwm_xwindow_t *xwin) { - xwin->pixmap = XCompositeNameWindowPixmap(vwm->display, xwin->id); - xwin->picture = XRenderCreatePicture(vwm->display, xwin->pixmap, - XRenderFindVisualFormat(vwm->display, xwin->attrs.visual), + xwin->pixmap = XCompositeNameWindowPixmap(VWM_XDISPLAY(vwm), xwin->id); + xwin->picture = XRenderCreatePicture(VWM_XDISPLAY(vwm), xwin->pixmap, + XRenderFindVisualFormat(VWM_XDISPLAY(vwm), xwin->attrs.visual), CPSubwindowMode, &pa_inferiors); - XFreePixmap(vwm->display, xwin->pixmap); + XFreePixmap(VWM_XDISPLAY(vwm), xwin->pixmap); } /* free the window's picture for accessing its redirected contents (compositing) */ static void unbind_namewindow(vwm_t *vwm, vwm_xwindow_t *xwin) { - XRenderFreePicture(vwm->display, xwin->picture); + XRenderFreePicture(VWM_XDISPLAY(vwm), xwin->picture); } void vwm_composite_xwin_create(vwm_t *vwm, vwm_xwindow_t *xwin) @@ -62,7 +62,7 @@ void vwm_composite_xwin_create(vwm_t *vwm, vwm_xwindow_t *xwin) if (!compositing_mode) return; bind_namewindow(vwm, xwin); - xwin->damage = XDamageCreate(vwm->display, xwin->id, XDamageReportNonEmpty); + xwin->damage = XDamageCreate(VWM_XDISPLAY(vwm), xwin->id, XDamageReportNonEmpty); } void vwm_composite_xwin_destroy(vwm_t *vwm, vwm_xwindow_t *xwin) @@ -70,15 +70,15 @@ void vwm_composite_xwin_destroy(vwm_t *vwm, vwm_xwindow_t *xwin) if (!compositing_mode) return; unbind_namewindow(vwm, xwin); - XDamageDestroy(vwm->display, xwin->damage); + XDamageDestroy(VWM_XDISPLAY(vwm), xwin->damage); } /* add damage to the global combined damage queue where we accumulate damage between calls to paint_all() */ void vwm_composite_damage_add(vwm_t *vwm, XserverRegion damage) { if (combined_damage != None) { - XFixesUnionRegion(vwm->display, combined_damage, combined_damage, damage); - XFixesDestroyRegion(vwm->display, damage); + XFixesUnionRegion(VWM_XDISPLAY(vwm), combined_damage, combined_damage, damage); + XFixesDestroyRegion(VWM_XDISPLAY(vwm), damage); } else { combined_damage = damage; } @@ -95,7 +95,7 @@ void vwm_composite_damage_win(vwm_t *vwm, vwm_xwindow_t *xwin) if (!compositing_mode) return; - region = XFixesCreateRegion(vwm->display, &rect, 1); + region = XFixesCreateRegion(VWM_XDISPLAY(vwm), &rect, 1); vwm_composite_damage_add(vwm, region); } @@ -114,7 +114,7 @@ void vwm_composite_handle_configure(vwm_t *vwm, vwm_xwindow_t *xwin, XWindowAttr new_attrs->width + new_attrs->border_width * 2, new_attrs->height + new_attrs->border_width * 2 } }; - region = XFixesCreateRegion(vwm->display, rects, 2); + region = XFixesCreateRegion(VWM_XDISPLAY(vwm), rects, 2); vwm_composite_damage_add(vwm, region); unbind_namewindow(vwm, xwin); bind_namewindow(vwm, xwin); @@ -141,9 +141,9 @@ void vwm_composite_damage_event(vwm_t *vwm, XDamageNotifyEvent *ev) return; } - region = XFixesCreateRegion(vwm->display, NULL, 0); - XDamageSubtract(vwm->display, xwin->damage, None, region); - XFixesTranslateRegion(vwm->display, region, xwin->attrs.x + xwin->attrs.border_width, xwin->attrs.y + xwin->attrs.border_width); + region = XFixesCreateRegion(VWM_XDISPLAY(vwm), NULL, 0); + XDamageSubtract(VWM_XDISPLAY(vwm), xwin->damage, None, region); + XFixesTranslateRegion(VWM_XDISPLAY(vwm), region, xwin->attrs.x + xwin->attrs.border_width, xwin->attrs.y + xwin->attrs.border_width); vwm_composite_damage_add(vwm, region); } @@ -154,9 +154,9 @@ void vwm_composite_invalidate_root(vwm_t *vwm) { if (!compositing_mode) return; - if (root_picture) XRenderFreePicture(vwm->display, root_picture); + if (root_picture) XRenderFreePicture(VWM_XDISPLAY(vwm), root_picture); root_picture = None; - if (root_buffer) XRenderFreePicture(vwm->display, root_picture); + if (root_buffer) XRenderFreePicture(VWM_XDISPLAY(vwm), root_picture); root_buffer = None; } @@ -181,19 +181,19 @@ void vwm_composite_paint_all(vwm_t *vwm) repaint_needed = 0; - if (!undamage_region) undamage_region = XFixesCreateRegion(vwm->display, NULL, 0); + if (!undamage_region) undamage_region = XFixesCreateRegion(VWM_XDISPLAY(vwm), NULL, 0); /* (re)create the root picture from the root window and allocate a double buffer for the off-screen composition of the damaged contents */ if (root_picture == None) { Pixmap root_pixmap; - XGetWindowAttributes(vwm->display, VWM_XROOT(vwm), &root_attrs); - root_picture = XRenderCreatePicture(vwm->display, VWM_XROOT(vwm), - XRenderFindVisualFormat(vwm->display, VWM_XVISUAL(vwm)), + XGetWindowAttributes(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), &root_attrs); + root_picture = XRenderCreatePicture(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), + XRenderFindVisualFormat(VWM_XDISPLAY(vwm), VWM_XVISUAL(vwm)), CPSubwindowMode, &pa_inferiors); - root_pixmap = XCreatePixmap(vwm->display, VWM_XROOT(vwm), root_attrs.width, root_attrs.height, VWM_XDEPTH(vwm)); - root_buffer = XRenderCreatePicture(vwm->display, root_pixmap, XRenderFindVisualFormat(vwm->display, VWM_XVISUAL(vwm)), 0, 0); - XFreePixmap(vwm->display, root_pixmap); + root_pixmap = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), root_attrs.width, root_attrs.height, VWM_XDEPTH(vwm)); + root_buffer = XRenderCreatePicture(VWM_XDISPLAY(vwm), root_pixmap, XRenderFindVisualFormat(VWM_XDISPLAY(vwm), VWM_XVISUAL(vwm)), 0, 0); + XFreePixmap(VWM_XDISPLAY(vwm), root_pixmap); } occluded = XCreateRegion(); @@ -234,8 +234,8 @@ void vwm_composite_paint_all(vwm_t *vwm) XDestroyRegion(occluded); /* start with the clip regions set to the damaged area accumulated since the previous paint_all() */ - XFixesSetPictureClipRegion(vwm->display, root_buffer, 0, 0, combined_damage); /* this is the double buffer where the in-flight screen contents are staged */ - XFixesSetPictureClipRegion(vwm->display, root_picture, 0, 0, combined_damage); /* this is the visible root window */ + XFixesSetPictureClipRegion(VWM_XDISPLAY(vwm), root_buffer, 0, 0, combined_damage); /* this is the double buffer where the in-flight screen contents are staged */ + XFixesSetPictureClipRegion(VWM_XDISPLAY(vwm), root_picture, 0, 0, combined_damage); /* this is the visible root window */ /* since translucent windows aren't supported in vwm, I can do this more efficiently */ list_for_each_entry_prev(xwin, &vwm->xwindows, xwindows) { @@ -250,14 +250,14 @@ void vwm_composite_paint_all(vwm_t *vwm) r.height = xwin->attrs.height + xwin->attrs.border_width * 2; /* render the redirected window contents into root_buffer, note root_buffer has the remaining combined_damage set as the clip region */ - XRenderComposite(vwm->display, PictOpSrc, xwin->picture, None, root_buffer, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, xwin->picture, None, root_buffer, 0, 0, 0, 0, /* src x, y, mask x, y */ r.x, r.y, /* dst x, y */ r.width, r.height); if (xwin->monitor && !xwin->attrs.override_redirect && xwin->overlay.width) { /* draw the monitoring overlay atop the window, note we stay within the window borders here. */ - XRenderComposite(vwm->display, PictOpOver, xwin->overlay.picture, None, root_buffer, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpOver, xwin->overlay.picture, None, root_buffer, 0, 0, 0, 0, /* src x,y, maxk x, y */ xwin->attrs.x + xwin->attrs.border_width, /* dst x */ xwin->attrs.y + xwin->attrs.border_width, /* dst y */ @@ -265,22 +265,22 @@ void vwm_composite_paint_all(vwm_t *vwm) } /* subtract the region of the window from the combined damage and update the root_buffer clip region to reflect the remaining damage */ - XFixesSetRegion(vwm->display, undamage_region, &r, 1); - XFixesSubtractRegion(vwm->display, combined_damage, combined_damage, undamage_region); - XFixesSetPictureClipRegion(vwm->display, root_buffer, 0, 0, combined_damage); + XFixesSetRegion(VWM_XDISPLAY(vwm), undamage_region, &r, 1); + XFixesSubtractRegion(VWM_XDISPLAY(vwm), combined_damage, combined_damage, undamage_region); + XFixesSetPictureClipRegion(VWM_XDISPLAY(vwm), root_buffer, 0, 0, combined_damage); } /* at this point all of the visible windows have been subtracted from the clip region, so paint any root window damage (draw background) */ - XRenderFillRectangle(vwm->display, PictOpSrc, root_buffer, &bgcolor, 0, 0, root_attrs.width, root_attrs.height); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, root_buffer, &bgcolor, 0, 0, root_attrs.width, root_attrs.height); /* discard the root_buffer clip region and copy root_buffer to root_picture, root_picture still has the combined damage as its clip region */ - XFixesSetPictureClipRegion(vwm->display, root_buffer, 0, 0, None); - XRenderComposite(vwm->display, PictOpSrc, root_buffer, None, root_picture, 0, 0, 0, 0, 0, 0, root_attrs.width, root_attrs.height); + XFixesSetPictureClipRegion(VWM_XDISPLAY(vwm), root_buffer, 0, 0, None); + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, root_buffer, None, root_picture, 0, 0, 0, 0, 0, 0, root_attrs.width, root_attrs.height); /* fin */ - XFixesDestroyRegion(vwm->display, combined_damage); + XFixesDestroyRegion(VWM_XDISPLAY(vwm), combined_damage); combined_damage = None; - XSync(vwm->display, False); + XSync(VWM_XDISPLAY(vwm), False); } @@ -289,21 +289,21 @@ void vwm_composite_toggle(vwm_t *vwm) { vwm_xwindow_t *xwin; - XGrabServer(vwm->display); - XSync(vwm->display, False); + XGrabServer(VWM_XDISPLAY(vwm)); + XSync(VWM_XDISPLAY(vwm), False); switch (compositing_mode) { case VWM_COMPOSITING_OFF: VWM_TRACE("enabling compositing"); compositing_mode = VWM_COMPOSITING_MONITORS; - XCompositeRedirectSubwindows(vwm->display, VWM_XROOT(vwm), CompositeRedirectManual); + XCompositeRedirectSubwindows(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), CompositeRedirectManual); list_for_each_entry_prev(xwin, &vwm->xwindows, xwindows) { bind_namewindow(vwm, xwin); - xwin->damage = XDamageCreate(vwm->display, xwin->id, XDamageReportNonEmpty); + xwin->damage = XDamageCreate(VWM_XDISPLAY(vwm), xwin->id, XDamageReportNonEmpty); } /* damage everything */ /* TODO: keep a list of rects reflecting all the current screens and create a region from that... */ - vwm_composite_damage_add(vwm, XFixesCreateRegionFromWindow(vwm->display, VWM_XROOT(vwm), WindowRegionBounding)); + vwm_composite_damage_add(vwm, XFixesCreateRegionFromWindow(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), WindowRegionBounding)); break; case VWM_COMPOSITING_MONITORS: { @@ -313,20 +313,20 @@ void vwm_composite_toggle(vwm_t *vwm) compositing_mode = VWM_COMPOSITING_OFF; list_for_each_entry_prev(xwin, &vwm->xwindows, xwindows) { unbind_namewindow(vwm, xwin); - XDamageDestroy(vwm->display, xwin->damage); + XDamageDestroy(VWM_XDISPLAY(vwm), xwin->damage); } - XCompositeUnredirectSubwindows(vwm->display, VWM_XROOT(vwm), CompositeRedirectManual); + XCompositeUnredirectSubwindows(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), CompositeRedirectManual); vwm_composite_invalidate_root(vwm); /* if there's any damage queued up discard it so we don't enter paint_all() until compositing is reenabled again. */ if (combined_damage) { - XFixesDestroyRegion(vwm->display, combined_damage); + XFixesDestroyRegion(VWM_XDISPLAY(vwm), combined_damage); combined_damage = None; } - while (XCheckTypedEvent(vwm->display, vwm->damage_event + XDamageNotify, &ev) != False); + while (XCheckTypedEvent(VWM_XDISPLAY(vwm), vwm->damage_event + XDamageNotify, &ev) != False); break; } } - XUngrabServer(vwm->display); + XUngrabServer(VWM_XDISPLAY(vwm)); } diff --git a/src/context.c b/src/context.c index cede8a9..70494cf 100644 --- a/src/context.c +++ b/src/context.c @@ -41,7 +41,7 @@ int vwm_context_focus(vwm_t *vwm, vwm_context_t desired_context) VWM_TRACE("unmapping shelf window \"%s\"", vwm->focused_shelf->xwindow->name); vwm_win_unmap(vwm, vwm->focused_shelf); - XFlush(vwm->display); /* for a more responsive feel */ + XFlush(VWM_XDISPLAY(vwm)); /* for a more responsive feel */ /* map the focused desktop, from the top of the stack down */ list_for_each_entry_prev(xwin, &vwm->xwindows, xwindows) { @@ -54,7 +54,7 @@ int vwm_context_focus(vwm_t *vwm, vwm_context_t desired_context) if (vwm->focused_desktop->focused_window) { VWM_TRACE("Focusing \"%s\"", vwm->focused_desktop->focused_window->xwindow->name); - XSetInputFocus(vwm->display, vwm->focused_desktop->focused_window->xwindow->id, RevertToPointerRoot, CurrentTime); + XSetInputFocus(VWM_XDISPLAY(vwm), vwm->focused_desktop->focused_window->xwindow->id, RevertToPointerRoot, CurrentTime); } vwm->focused_context = VWM_CONTEXT_DESKTOP; @@ -77,7 +77,7 @@ int vwm_context_focus(vwm_t *vwm, vwm_context_t desired_context) } } - XFlush(vwm->display); /* for a more responsive feel */ + XFlush(VWM_XDISPLAY(vwm)); /* for a more responsive feel */ VWM_TRACE("Mapping shelf window \"%s\"", vwm->focused_shelf->xwindow->name); vwm_win_map(vwm, vwm->focused_shelf); diff --git a/src/desktop.c b/src/desktop.c index fb342f4..2b5548a 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -39,8 +39,8 @@ void vwm_desktop_mru(vwm_t *vwm, vwm_desktop_t *desktop) /* this switches to the desktop context if necessary, maps and unmaps windows accordingly if necessary */ int vwm_desktop_focus(vwm_t *vwm, vwm_desktop_t *desktop) { - XGrabServer(vwm->display); - XSync(vwm->display, False); + XGrabServer(VWM_XDISPLAY(vwm)); + XSync(VWM_XDISPLAY(vwm), False); /* if the context switched and the focused desktop is the desired desktop there's nothing else to do */ if ((vwm_context_focus(vwm, VWM_CONTEXT_DESKTOP) && vwm->focused_desktop != desktop) || vwm->focused_desktop != desktop) { @@ -53,7 +53,7 @@ int vwm_desktop_focus(vwm_t *vwm, vwm_desktop_t *desktop) if (vwin->desktop == vwm->focused_desktop) vwm_win_unmap(vwm, vwin); } - XFlush(vwm->display); + XFlush(VWM_XDISPLAY(vwm)); list_for_each_entry_prev(xwin, &vwm->xwindows, xwindows) { if (!(vwin = xwin->managed) || vwin->shelved) continue; @@ -66,10 +66,10 @@ int vwm_desktop_focus(vwm_t *vwm, vwm_desktop_t *desktop) /* directly focus the desktop's focused window if there is one, we don't use vwm_win_focus() intentionally XXX */ if (vwm->focused_desktop->focused_window) { VWM_TRACE("Focusing \"%s\"", vwm->focused_desktop->focused_window->xwindow->name); - XSetInputFocus(vwm->display, vwm->focused_desktop->focused_window->xwindow->id, RevertToPointerRoot, CurrentTime); + XSetInputFocus(VWM_XDISPLAY(vwm), vwm->focused_desktop->focused_window->xwindow->id, RevertToPointerRoot, CurrentTime); } - XUngrabServer(vwm->display); + XUngrabServer(VWM_XDISPLAY(vwm)); return 1; } @@ -35,7 +35,7 @@ static int keys_pressed(vwm_t *vwm) { int i; char state[32]; - XQueryKeymap(vwm->display, state); + XQueryKeymap(VWM_XDISPLAY(vwm), state); for (i = 0; i < sizeof(state); i++) { if (state[i]) return 1; @@ -80,8 +80,8 @@ void vwm_key_released(vwm_t *vwm, Window win, XKeyReleasedEvent *keyrelease) } if (key_is_grabbed && !keys_pressed(vwm)) { - XUngrabKeyboard(vwm->display, CurrentTime); - XFlush(vwm->display); + XUngrabKeyboard(VWM_XDISPLAY(vwm), CurrentTime); + XFlush(VWM_XDISPLAY(vwm)); key_is_grabbed = 0; vwm->fence_mask = 0; /* reset the fence mask on release for VWM_FENCE_MASKED_VIOLATE */ } @@ -160,7 +160,7 @@ void vwm_key_pressed(vwm_t *vwm, Window win, XKeyPressedEvent *keypress) case XK_d: /* destroy focused */ if (vwin) { if (keypress->state & ShiftMask) { /* brutally destroy the focused window */ - XKillClient(vwm->display, vwin->xwindow->id); + XKillClient(VWM_XDISPLAY(vwm), vwin->xwindow->id); } else { /* kindly destroy the focused window */ vwm_xwin_message(vwm, vwin->xwindow, vwm->wm_protocols_atom, vwm->wm_delete_atom); } @@ -240,7 +240,7 @@ void vwm_key_pressed(vwm_t *vwm, Window win, XKeyPressedEvent *keypress) } else { do_grab = 1; - XRaiseWindow(vwm->display, vwin->xwindow->id); + XRaiseWindow(VWM_XDISPLAY(vwm), vwin->xwindow->id); if (repeat_cnt == 1) { /* double: reraise & fullscreen */ @@ -257,7 +257,7 @@ void vwm_key_pressed(vwm_t *vwm, Window win, XKeyPressedEvent *keypress) vwm_win_autoconf(vwm, vwin, VWM_SCREEN_REL_TOTAL, VWM_WIN_AUTOCONF_ALL); } } - XFlush(vwm->display); + XFlush(VWM_XDISPLAY(vwm)); } } break; @@ -273,9 +273,9 @@ void vwm_key_pressed(vwm_t *vwm, Window win, XKeyPressedEvent *keypress) if (vwin->autoconfigured == VWM_WIN_AUTOCONF_ALL) { vwm_win_autoconf(vwm, vwin, VWM_SCREEN_REL_XWIN, VWM_WIN_AUTOCONF_FULL); } else { - XLowerWindow(vwm->display, vwin->xwindow->id); + XLowerWindow(VWM_XDISPLAY(vwm), vwin->xwindow->id); } - XFlush(vwm->display); + XFlush(VWM_XDISPLAY(vwm)); } } break; @@ -361,7 +361,7 @@ void vwm_key_pressed(vwm_t *vwm, Window win, XKeyPressedEvent *keypress) if (!key_is_grabbed && do_grab) { VWM_TRACE("saving focused_origin of %p", vwin); vwm->focused_origin = vwin; /* for returning to on abort */ - XGrabKeyboard(vwm->display, VWM_XROOT(vwm), False, GrabModeAsync, GrabModeAsync, CurrentTime); + XGrabKeyboard(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), False, GrabModeAsync, GrabModeAsync, CurrentTime); key_is_grabbed = 1; } @@ -33,7 +33,7 @@ void vwm_draw_logo(vwm_t *vwm) XPoint points[VWM_LOGO_POINTS]; const vwm_screen_t *scr = vwm_screen_find(vwm, VWM_SCREEN_REL_POINTER); - XGrabServer(vwm->display); + XGrabServer(VWM_XDISPLAY(vwm)); /* use the dimensions of the pointer-containing screen */ width = scr->width; @@ -50,11 +50,11 @@ void vwm_draw_logo(vwm_t *vwm) points[i].y = (i % 2 * (float)height) + yoff; } - XDrawLines(vwm->display, VWM_XROOT(vwm), vwm->gc, points, sizeof(points) / sizeof(XPoint), CoordModeOrigin); - XFlush(vwm->display); + XDrawLines(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), VWM_XGC(vwm), points, sizeof(points) / sizeof(XPoint), CoordModeOrigin); + XFlush(VWM_XDISPLAY(vwm)); usleep(3333); - XDrawLines(vwm->display, VWM_XROOT(vwm), vwm->gc, points, sizeof(points) / sizeof(XPoint), CoordModeOrigin); - XFlush(vwm->display); + XDrawLines(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), VWM_XGC(vwm), points, sizeof(points) / sizeof(XPoint), CoordModeOrigin); + XFlush(VWM_XDISPLAY(vwm)); /* the width is shrunken as well, but only by as much as it is tall */ yoff++; @@ -62,5 +62,5 @@ void vwm_draw_logo(vwm_t *vwm) xoff += 2; } - XUngrabServer(vwm->display); + XUngrabServer(VWM_XDISPLAY(vwm)); } diff --git a/src/overlay.c b/src/overlay.c index 2dc572e..2616cce 100644 --- a/src/overlay.c +++ b/src/overlay.c @@ -101,7 +101,7 @@ static void snowflake_row(vwm_t *vwm, vwm_xwindow_t *xwin, Picture pic, int copy if (copy) { /* copy row to tmp */ - XRenderComposite(vwm->display, PictOpSrc, pic, None, xwin->overlay.tmp_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, pic, None, xwin->overlay.tmp_picture, 0, row * OVERLAY_ROW_HEIGHT, /* src */ 0, 0, /* mask */ 0, 0, /* dest */ @@ -109,24 +109,24 @@ static void snowflake_row(vwm_t *vwm, vwm_xwindow_t *xwin, Picture pic, int copy } /* shift up */ - XRenderChangePicture(vwm->display, pic, CPRepeat, &pa_no_repeat); - XRenderComposite(vwm->display, PictOpSrc, pic, None, pic, + XRenderChangePicture(VWM_XDISPLAY(vwm), pic, CPRepeat, &pa_no_repeat); + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, pic, None, pic, 0, (1 + row) * OVERLAY_ROW_HEIGHT, /* src */ 0, 0, /* mask */ 0, row * OVERLAY_ROW_HEIGHT, /* dest */ xwin->overlay.width, (1 + xwin->overlay.heirarchy_end) * OVERLAY_ROW_HEIGHT - (1 + row) * OVERLAY_ROW_HEIGHT); /* dimensions */ - XRenderChangePicture(vwm->display, pic, CPRepeat, &pa_repeat); + XRenderChangePicture(VWM_XDISPLAY(vwm), pic, CPRepeat, &pa_repeat); if (copy) { /* copy tmp to top of snowflakes */ - XRenderComposite(vwm->display, PictOpSrc, xwin->overlay.tmp_picture, None, pic, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.tmp_picture, None, pic, 0, 0, /* src */ 0, 0, /* mask */ 0, (xwin->overlay.heirarchy_end) * OVERLAY_ROW_HEIGHT, /* dest */ xwin->overlay.width, OVERLAY_ROW_HEIGHT); /* dimensions */ } else { /* clear the snowflake row */ - XRenderFillRectangle(vwm->display, PictOpSrc, pic, &overlay_trans_color, + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, pic, &overlay_trans_color, 0, (xwin->overlay.heirarchy_end) * OVERLAY_ROW_HEIGHT, /* dest */ xwin->overlay.width, OVERLAY_ROW_HEIGHT); /* dimensions */ } @@ -142,13 +142,13 @@ static void allocate_row(vwm_t *vwm, vwm_xwindow_t *xwin, Picture pic, int row) VWM_TRACE("pid=%i xwin=%p row=%i", xwin->monitor->pid, xwin, row); /* shift everything below the row down */ - XRenderComposite(vwm->display, PictOpSrc, pic, None, pic, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, pic, None, pic, 0, row * OVERLAY_ROW_HEIGHT, /* src */ 0, 0, /* mask */ 0, (1 + row) * OVERLAY_ROW_HEIGHT, /* dest */ xwin->overlay.width, xwin->overlay.height - (1 + row) * OVERLAY_ROW_HEIGHT); /* dimensions */ /* fill the space created with transparent pixels */ - XRenderFillRectangle(vwm->display, PictOpSrc, pic, &overlay_trans_color, + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, pic, &overlay_trans_color, 0, row * OVERLAY_ROW_HEIGHT, /* dest */ xwin->overlay.width, OVERLAY_ROW_HEIGHT); /* dimensions */ } @@ -158,25 +158,25 @@ static void allocate_row(vwm_t *vwm, vwm_xwindow_t *xwin, Picture pic, int row) static void shadow_row(vwm_t *vwm, vwm_xwindow_t *xwin, int row) { /* the current technique for creating the shadow is to simply render the text at +1/-1 pixel offsets on both axis in translucent black */ - XRenderComposite(vwm->display, PictOpSrc, overlay_shadow_fill, xwin->overlay.text_picture, xwin->overlay.shadow_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, overlay_shadow_fill, xwin->overlay.text_picture, xwin->overlay.shadow_picture, 0, 0, -1, row * OVERLAY_ROW_HEIGHT, 0, row * OVERLAY_ROW_HEIGHT, xwin->attrs.width, OVERLAY_ROW_HEIGHT); - XRenderComposite(vwm->display, PictOpOver, overlay_shadow_fill, xwin->overlay.text_picture, xwin->overlay.shadow_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpOver, overlay_shadow_fill, xwin->overlay.text_picture, xwin->overlay.shadow_picture, 0, 0, 0, -1 + row * OVERLAY_ROW_HEIGHT, 0, row * OVERLAY_ROW_HEIGHT, xwin->attrs.width, OVERLAY_ROW_HEIGHT); - XRenderComposite(vwm->display, PictOpOver, overlay_shadow_fill, xwin->overlay.text_picture, xwin->overlay.shadow_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpOver, overlay_shadow_fill, xwin->overlay.text_picture, xwin->overlay.shadow_picture, 0, 0, 1, row * OVERLAY_ROW_HEIGHT, 0, row * OVERLAY_ROW_HEIGHT, xwin->attrs.width, OVERLAY_ROW_HEIGHT); - XRenderComposite(vwm->display, PictOpOver, overlay_shadow_fill, xwin->overlay.text_picture, xwin->overlay.shadow_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpOver, overlay_shadow_fill, xwin->overlay.text_picture, xwin->overlay.shadow_picture, 0, 0, 0, 1 + row * OVERLAY_ROW_HEIGHT, 0, row * OVERLAY_ROW_HEIGHT, @@ -275,10 +275,10 @@ static void draw_bars(vwm_t *vwm, vwm_xwindow_t *xwin, int row, double a_fractio if (b_fraction && !b_height) b_height = 1; /* draw the two bars for this sample at the current phase in the graphs, note the first is ceiling-based, second floor-based */ - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.grapha_picture, &overlay_visible_color, + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.grapha_picture, &overlay_visible_color, xwin->overlay.phase, row * OVERLAY_ROW_HEIGHT, /* dst x, y */ 1, a_height); /* dst w, h */ - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.graphb_picture, &overlay_visible_color, + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.graphb_picture, &overlay_visible_color, xwin->overlay.phase, row * OVERLAY_ROW_HEIGHT + (OVERLAY_ROW_HEIGHT - b_height) - 1, /* dst x, y */ 1, b_height); /* dst w, h */ } @@ -307,7 +307,7 @@ static void draw_heirarchy_row(vwm_t *vwm, vwm_xwindow_t *xwin, vmon_proc_t *pro /* TODO: make the columns interactively configurable @ runtime */ if (!proc->is_new) { /* XXX for now always clear the row, this should be capable of being optimized in the future (if the datums driving the text haven't changed...) */ - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.text_picture, &overlay_trans_color, + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.text_picture, &overlay_trans_color, 0, row * OVERLAY_ROW_HEIGHT, /* dst x, y */ xwin->overlay.width, OVERLAY_ROW_HEIGHT); /* dst w, h */ } @@ -327,18 +327,18 @@ static void draw_heirarchy_row(vwm_t *vwm, vwm_xwindow_t *xwin, vmon_proc_t *pro /* the process' comm label indented according to depth, followed with their respective argv's */ argv2xtext(proc, items, NELEMS(items), &nr_items); - XDrawText(vwm->display, xwin->overlay.text_pixmap, text_gc, + XDrawText(VWM_XDISPLAY(vwm), xwin->overlay.text_pixmap, text_gc, depth * (OVERLAY_ROW_HEIGHT / 2), (row + 1) * OVERLAY_ROW_HEIGHT - 3, /* dst x, y */ items, nr_items); /* ensure the area for the rest of the stuff is cleared, we don't put much text into thread rows so skip it for those. */ if (!proc->is_thread) { - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.text_picture, &overlay_trans_color, + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.text_picture, &overlay_trans_color, xwin->attrs.width - str_width, row * OVERLAY_ROW_HEIGHT, /* dst x,y */ xwin->overlay.width - (xwin->attrs.width - str_width), OVERLAY_ROW_HEIGHT); /* dst w,h */ } - XDrawString(vwm->display, xwin->overlay.text_pixmap, text_gc, + XDrawString(VWM_XDISPLAY(vwm), xwin->overlay.text_pixmap, text_gc, xwin->attrs.width - str_width, (row + 1) * OVERLAY_ROW_HEIGHT - 3, /* dst x, y */ str, str_len); @@ -361,7 +361,7 @@ static void draw_heirarchy_row(vwm_t *vwm, vwm_xwindow_t *xwin, vmon_proc_t *pro /* determine if the ancestor has remaining siblings which are not stale, if so, draw a connecting bar at its depth */ for (rem = ancestor->siblings.next; rem != &ancestor->parent->children; rem = rem->next) { if (!(list_entry(rem, vmon_proc_t, siblings)->is_stale)) { - XDrawLine(vwm->display, xwin->overlay.text_pixmap, text_gc, + XDrawLine(VWM_XDISPLAY(vwm), xwin->overlay.text_pixmap, text_gc, bar_x, bar_y - OVERLAY_ROW_HEIGHT, /* dst x1, y1 */ bar_x, bar_y); /* dst x2, y2 (vertical line) */ break; /* stop looking for more siblings at this ancestor when we find one that isn't stale */ @@ -410,16 +410,16 @@ static void draw_heirarchy_row(vwm_t *vwm, vwm_xwindow_t *xwin, vmon_proc_t *pro /* if we're the last sibling, corner the tee by shortening the vbar */ if (proc == last_sibling) { - XDrawLine(vwm->display, xwin->overlay.text_pixmap, text_gc, + XDrawLine(VWM_XDISPLAY(vwm), xwin->overlay.text_pixmap, text_gc, bar_x, bar_y - OVERLAY_ROW_HEIGHT, /* dst x1, y1 */ bar_x, bar_y - 4); /* dst x2, y2 (vertical bar) */ } else { - XDrawLine(vwm->display, xwin->overlay.text_pixmap, text_gc, + XDrawLine(VWM_XDISPLAY(vwm), xwin->overlay.text_pixmap, text_gc, bar_x, bar_y - OVERLAY_ROW_HEIGHT, /* dst x1, y1 */ bar_x, bar_y); /* dst x2, y2 (vertical bar) */ } - XDrawLine(vwm->display, xwin->overlay.text_pixmap, text_gc, + XDrawLine(VWM_XDISPLAY(vwm), xwin->overlay.text_pixmap, text_gc, bar_x, bar_y - 4, /* dst x1, y1 */ bar_x + 2, bar_y - 4); /* dst x2, y2 (horizontal bar) */ @@ -487,12 +487,12 @@ static void draw_overlay_rest(vwm_t *vwm, vwm_xwindow_t *xwin, vmon_proc_t *proc (*depth), (*row), proc->is_thread); /* stamp the graphs with the finish line */ - XRenderComposite(vwm->display, PictOpSrc, overlay_finish_fill, None, xwin->overlay.grapha_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, overlay_finish_fill, None, xwin->overlay.grapha_picture, 0, 0, /* src x, y */ 0, 0, /* mask x, y */ xwin->overlay.phase, (*row) * OVERLAY_ROW_HEIGHT, /* dst x, y */ 1, OVERLAY_ROW_HEIGHT - 1); - XRenderComposite(vwm->display, PictOpSrc, overlay_finish_fill, None, xwin->overlay.graphb_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, overlay_finish_fill, None, xwin->overlay.graphb_picture, 0, 0, /* src x, y */ 0, 0, /* mask x, y */ xwin->overlay.phase, (*row) * OVERLAY_ROW_HEIGHT, /* dst x, y */ @@ -507,7 +507,7 @@ static void draw_overlay_rest(vwm_t *vwm, vwm_xwindow_t *xwin, vmon_proc_t *proc /* stamp the name (and whatever else we include) into overlay.text_picture */ argv2xtext(proc, items, NELEMS(items), &nr_items); - XDrawText(vwm->display, xwin->overlay.text_pixmap, text_gc, + XDrawText(VWM_XDISPLAY(vwm), xwin->overlay.text_pixmap, text_gc, 5, (xwin->overlay.heirarchy_end + 1) * OVERLAY_ROW_HEIGHT - 3,/* dst x, y */ items, nr_items); shadow_row(vwm, xwin, xwin->overlay.heirarchy_end); @@ -594,11 +594,11 @@ static void draw_overlay(vwm_t *vwm, vwm_xwindow_t *xwin, vmon_proc_t *proc, int /* only draw the \/\/\ and HZ if necessary */ if (xwin->overlay.redraw_needed || prev_sampling_interval != sampling_interval) { snprintf(str, sizeof(str), "\\/\\/\\ %2iHz %n", (int)(sampling_interval < 0 ? 0 : 1 / sampling_intervals[sampling_interval]), &str_len); - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.text_picture, &overlay_trans_color, + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.text_picture, &overlay_trans_color, 0, 0, /* dst x, y */ xwin->attrs.width, OVERLAY_ROW_HEIGHT); /* dst w, h */ str_width = XTextWidth(overlay_font, str, str_len); - XDrawString(vwm->display, xwin->overlay.text_pixmap, text_gc, + XDrawString(VWM_XDISPLAY(vwm), xwin->overlay.text_pixmap, text_gc, xwin->attrs.width - str_width, OVERLAY_ROW_HEIGHT - 3, /* dst x, y */ str, str_len); shadow_row(vwm, xwin, 0); @@ -647,76 +647,76 @@ static void maintain_overlay(vwm_t *vwm, vwm_xwindow_t *xwin) xwin->overlay.width = MAX(xwin->overlay.width, MAX(xwin->attrs.width, OVERLAY_GRAPH_MIN_WIDTH)); xwin->overlay.height = MAX(xwin->overlay.height, MAX(xwin->attrs.height, OVERLAY_GRAPH_MIN_HEIGHT)); - pixmap = XCreatePixmap(vwm->display, VWM_XROOT(vwm), xwin->overlay.width, xwin->overlay.height, OVERLAY_MASK_DEPTH); - xwin->overlay.grapha_picture = XRenderCreatePicture(vwm->display, pixmap, XRenderFindStandardFormat(vwm->display, OVERLAY_MASK_FORMAT), CPRepeat, &pa_repeat); - XFreePixmap(vwm->display, pixmap); - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.grapha_picture, &overlay_trans_color, 0, 0, xwin->overlay.width, xwin->overlay.height); + pixmap = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), xwin->overlay.width, xwin->overlay.height, OVERLAY_MASK_DEPTH); + xwin->overlay.grapha_picture = XRenderCreatePicture(VWM_XDISPLAY(vwm), pixmap, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), OVERLAY_MASK_FORMAT), CPRepeat, &pa_repeat); + XFreePixmap(VWM_XDISPLAY(vwm), pixmap); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.grapha_picture, &overlay_trans_color, 0, 0, xwin->overlay.width, xwin->overlay.height); - pixmap = XCreatePixmap(vwm->display, VWM_XROOT(vwm), xwin->overlay.width, xwin->overlay.height, OVERLAY_MASK_DEPTH); - xwin->overlay.graphb_picture = XRenderCreatePicture(vwm->display, pixmap, XRenderFindStandardFormat(vwm->display, OVERLAY_MASK_FORMAT), CPRepeat, &pa_repeat); - XFreePixmap(vwm->display, pixmap); - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.graphb_picture, &overlay_trans_color, 0, 0, xwin->overlay.width, xwin->overlay.height); + pixmap = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), xwin->overlay.width, xwin->overlay.height, OVERLAY_MASK_DEPTH); + xwin->overlay.graphb_picture = XRenderCreatePicture(VWM_XDISPLAY(vwm), pixmap, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), OVERLAY_MASK_FORMAT), CPRepeat, &pa_repeat); + XFreePixmap(VWM_XDISPLAY(vwm), pixmap); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.graphb_picture, &overlay_trans_color, 0, 0, xwin->overlay.width, xwin->overlay.height); - pixmap = XCreatePixmap(vwm->display, VWM_XROOT(vwm), xwin->overlay.width, OVERLAY_ROW_HEIGHT, OVERLAY_MASK_DEPTH); - xwin->overlay.tmp_picture = XRenderCreatePicture(vwm->display, pixmap, XRenderFindStandardFormat(vwm->display, OVERLAY_MASK_FORMAT), 0, NULL); - XFreePixmap(vwm->display, pixmap); + pixmap = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), xwin->overlay.width, OVERLAY_ROW_HEIGHT, OVERLAY_MASK_DEPTH); + xwin->overlay.tmp_picture = XRenderCreatePicture(VWM_XDISPLAY(vwm), pixmap, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), OVERLAY_MASK_FORMAT), 0, NULL); + XFreePixmap(VWM_XDISPLAY(vwm), pixmap); /* keep the text_pixmap reference around for XDrawText usage */ - xwin->overlay.text_pixmap = XCreatePixmap(vwm->display, VWM_XROOT(vwm), xwin->overlay.width, xwin->overlay.height, OVERLAY_MASK_DEPTH); - xwin->overlay.text_picture = XRenderCreatePicture(vwm->display, xwin->overlay.text_pixmap, XRenderFindStandardFormat(vwm->display, OVERLAY_MASK_FORMAT), 0, NULL); - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.text_picture, &overlay_trans_color, 0, 0, xwin->overlay.width, xwin->overlay.height); + xwin->overlay.text_pixmap = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), xwin->overlay.width, xwin->overlay.height, OVERLAY_MASK_DEPTH); + xwin->overlay.text_picture = XRenderCreatePicture(VWM_XDISPLAY(vwm), xwin->overlay.text_pixmap, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), OVERLAY_MASK_FORMAT), 0, NULL); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.text_picture, &overlay_trans_color, 0, 0, xwin->overlay.width, xwin->overlay.height); - pixmap = XCreatePixmap(vwm->display, VWM_XROOT(vwm), xwin->overlay.width, xwin->overlay.height, OVERLAY_MASK_DEPTH); - xwin->overlay.shadow_picture = XRenderCreatePicture(vwm->display, pixmap, XRenderFindStandardFormat(vwm->display, OVERLAY_MASK_FORMAT), 0, NULL); - XFreePixmap(vwm->display, pixmap); - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.shadow_picture, &overlay_trans_color, 0, 0, xwin->overlay.width, xwin->overlay.height); + pixmap = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), xwin->overlay.width, xwin->overlay.height, OVERLAY_MASK_DEPTH); + xwin->overlay.shadow_picture = XRenderCreatePicture(VWM_XDISPLAY(vwm), pixmap, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), OVERLAY_MASK_FORMAT), 0, NULL); + XFreePixmap(VWM_XDISPLAY(vwm), pixmap); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.shadow_picture, &overlay_trans_color, 0, 0, xwin->overlay.width, xwin->overlay.height); - pixmap = XCreatePixmap(vwm->display, VWM_XROOT(vwm), xwin->overlay.width, xwin->overlay.height, 32); - xwin->overlay.picture = XRenderCreatePicture(vwm->display, pixmap, XRenderFindStandardFormat(vwm->display, PictStandardARGB32), 0, NULL); - XFreePixmap(vwm->display, pixmap); + pixmap = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), xwin->overlay.width, xwin->overlay.height, 32); + xwin->overlay.picture = XRenderCreatePicture(VWM_XDISPLAY(vwm), pixmap, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), PictStandardARGB32), 0, NULL); + XFreePixmap(VWM_XDISPLAY(vwm), pixmap); if (existing.width) { /* XXX: note the graph pictures are copied from their current phase in the x dimension */ - XRenderComposite(vwm->display, PictOpSrc, existing.grapha_picture, None, xwin->overlay.grapha_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, existing.grapha_picture, None, xwin->overlay.grapha_picture, existing.phase, 0, /* src x, y */ 0, 0, /* mask x, y */ 0, 0, /* dest x, y */ existing.width, existing.height); - XRenderComposite(vwm->display, PictOpSrc, existing.graphb_picture, None, xwin->overlay.graphb_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, existing.graphb_picture, None, xwin->overlay.graphb_picture, existing.phase, 0, /* src x, y */ 0, 0, /* mask x, y */ 0, 0, /* dest x, y */ existing.width, existing.height); - XRenderComposite(vwm->display, PictOpSrc, existing.text_picture, None, xwin->overlay.text_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, existing.text_picture, None, xwin->overlay.text_picture, 0, 0, /* src x, y */ 0, 0, /* mask x, y */ 0, 0, /* dest x, y */ existing.width, existing.height); - XRenderComposite(vwm->display, PictOpSrc, existing.shadow_picture, None, xwin->overlay.shadow_picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, existing.shadow_picture, None, xwin->overlay.shadow_picture, 0, 0, /* src x, y */ 0, 0, /* mask x, y */ 0, 0, /* dest x, y */ existing.width, existing.height); - XRenderComposite(vwm->display, PictOpSrc, existing.picture, None, xwin->overlay.picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, existing.picture, None, xwin->overlay.picture, 0, 0, /* src x, y */ 0, 0, /* mask x, y */ 0, 0, /* dest x, y */ existing.width, existing.height); xwin->overlay.phase = 0; /* having unrolled the existing graph[ab] pictures into the larger ones, phase is reset to 0 */ - XRenderFreePicture(vwm->display, existing.grapha_picture); - XRenderFreePicture(vwm->display, existing.graphb_picture); - XRenderFreePicture(vwm->display, existing.tmp_picture); - XRenderFreePicture(vwm->display, existing.text_picture); - XFreePixmap(vwm->display, existing.text_pixmap); - XRenderFreePicture(vwm->display, existing.shadow_picture); - XRenderFreePicture(vwm->display, existing.picture); + XRenderFreePicture(VWM_XDISPLAY(vwm), existing.grapha_picture); + XRenderFreePicture(VWM_XDISPLAY(vwm), existing.graphb_picture); + XRenderFreePicture(VWM_XDISPLAY(vwm), existing.tmp_picture); + XRenderFreePicture(VWM_XDISPLAY(vwm), existing.text_picture); + XFreePixmap(VWM_XDISPLAY(vwm), existing.text_pixmap); + XRenderFreePicture(VWM_XDISPLAY(vwm), existing.shadow_picture); + XRenderFreePicture(VWM_XDISPLAY(vwm), existing.picture); } } xwin->overlay.phase += (xwin->overlay.width - 1); /* simply change this to .phase++ to scroll the other direction */ xwin->overlay.phase %= xwin->overlay.width; - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.grapha_picture, &overlay_trans_color, xwin->overlay.phase, 0, 1, xwin->overlay.height); - XRenderFillRectangle(vwm->display, PictOpSrc, xwin->overlay.graphb_picture, &overlay_trans_color, xwin->overlay.phase, 0, 1, xwin->overlay.height); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.grapha_picture, &overlay_trans_color, xwin->overlay.phase, 0, 1, xwin->overlay.height); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, xwin->overlay.graphb_picture, &overlay_trans_color, xwin->overlay.phase, 0, 1, xwin->overlay.height); /* recursively draw the monitored processes to the overlay */ draw_overlay(vwm, xwin, xwin->monitor, &depth, &row); @@ -805,44 +805,44 @@ static void init_overlay(vwm_t *vwm) { gettimeofday(&this_sample, NULL); /* get all the text and graphics stuff setup for overlays */ - overlay_font = XLoadQueryFont(vwm->display, OVERLAY_FIXED_FONT); + overlay_font = XLoadQueryFont(VWM_XDISPLAY(vwm), OVERLAY_FIXED_FONT); /* create a GC for rendering the text using Xlib into the text overlay stencils */ - bitmask = XCreatePixmap(vwm->display, VWM_XROOT(vwm), 1, 1, OVERLAY_MASK_DEPTH); - text_gc = XCreateGC(vwm->display, bitmask, 0, NULL); - XSetForeground(vwm->display, text_gc, WhitePixel(vwm->display, vwm->screen_num)); - XFreePixmap(vwm->display, bitmask); + bitmask = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), 1, 1, OVERLAY_MASK_DEPTH); + text_gc = XCreateGC(VWM_XDISPLAY(vwm), bitmask, 0, NULL); + XSetForeground(VWM_XDISPLAY(vwm), text_gc, WhitePixel(VWM_XDISPLAY(vwm), VWM_XSCREENNUM(vwm))); + XFreePixmap(VWM_XDISPLAY(vwm), bitmask); /* create some repeating source fill pictures for drawing through the text and graph stencils */ - bitmask = XCreatePixmap(vwm->display, VWM_XROOT(vwm), 1, 1, 32); - overlay_text_fill = XRenderCreatePicture(vwm->display, bitmask, XRenderFindStandardFormat(vwm->display, PictStandardARGB32), CPRepeat, &pa_repeat); - XRenderFillRectangle(vwm->display, PictOpSrc, overlay_text_fill, &overlay_visible_color, 0, 0, 1, 1); - - bitmask = XCreatePixmap(vwm->display, VWM_XROOT(vwm), 1, 1, 32); - overlay_shadow_fill = XRenderCreatePicture(vwm->display, bitmask, XRenderFindStandardFormat(vwm->display, PictStandardARGB32), CPRepeat, &pa_repeat); - XRenderFillRectangle(vwm->display, PictOpSrc, overlay_shadow_fill, &overlay_shadow_color, 0, 0, 1, 1); - - bitmask = XCreatePixmap(vwm->display, VWM_XROOT(vwm), 1, OVERLAY_ROW_HEIGHT, 32); - overlay_bg_fill = XRenderCreatePicture(vwm->display, bitmask, XRenderFindStandardFormat(vwm->display, PictStandardARGB32), CPRepeat, &pa_repeat); - XRenderFillRectangle(vwm->display, PictOpSrc, overlay_bg_fill, &overlay_bg_color, 0, 0, 1, OVERLAY_ROW_HEIGHT); - XRenderFillRectangle(vwm->display, PictOpSrc, overlay_bg_fill, &overlay_div_color, 0, OVERLAY_ROW_HEIGHT - 1, 1, 1); - - bitmask = XCreatePixmap(vwm->display, VWM_XROOT(vwm), 1, 1, 32); - overlay_snowflakes_text_fill = XRenderCreatePicture(vwm->display, bitmask, XRenderFindStandardFormat(vwm->display, PictStandardARGB32), CPRepeat, &pa_repeat); - XRenderFillRectangle(vwm->display, PictOpSrc, overlay_snowflakes_text_fill, &overlay_snowflakes_visible_color, 0, 0, 1, 1); - - bitmask = XCreatePixmap(vwm->display, VWM_XROOT(vwm), 1, 1, 32); - overlay_grapha_fill = XRenderCreatePicture(vwm->display, bitmask, XRenderFindStandardFormat(vwm->display, PictStandardARGB32), CPRepeat, &pa_repeat); - XRenderFillRectangle(vwm->display, PictOpSrc, overlay_grapha_fill, &overlay_grapha_color, 0, 0, 1, 1); - - bitmask = XCreatePixmap(vwm->display, VWM_XROOT(vwm), 1, 1, 32); - overlay_graphb_fill = XRenderCreatePicture(vwm->display, bitmask, XRenderFindStandardFormat(vwm->display, PictStandardARGB32), CPRepeat, &pa_repeat); - XRenderFillRectangle(vwm->display, PictOpSrc, overlay_graphb_fill, &overlay_graphb_color, 0, 0, 1, 1); - - bitmask = XCreatePixmap(vwm->display, VWM_XROOT(vwm), 1, 2, 32); - overlay_finish_fill = XRenderCreatePicture(vwm->display, bitmask, XRenderFindStandardFormat(vwm->display, PictStandardARGB32), CPRepeat, &pa_repeat); - XRenderFillRectangle(vwm->display, PictOpSrc, overlay_finish_fill, &overlay_visible_color, 0, 0, 1, 1); - XRenderFillRectangle(vwm->display, PictOpSrc, overlay_finish_fill, &overlay_trans_color, 0, 1, 1, 1); + bitmask = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), 1, 1, 32); + overlay_text_fill = XRenderCreatePicture(VWM_XDISPLAY(vwm), bitmask, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), PictStandardARGB32), CPRepeat, &pa_repeat); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, overlay_text_fill, &overlay_visible_color, 0, 0, 1, 1); + + bitmask = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), 1, 1, 32); + overlay_shadow_fill = XRenderCreatePicture(VWM_XDISPLAY(vwm), bitmask, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), PictStandardARGB32), CPRepeat, &pa_repeat); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, overlay_shadow_fill, &overlay_shadow_color, 0, 0, 1, 1); + + bitmask = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), 1, OVERLAY_ROW_HEIGHT, 32); + overlay_bg_fill = XRenderCreatePicture(VWM_XDISPLAY(vwm), bitmask, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), PictStandardARGB32), CPRepeat, &pa_repeat); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, overlay_bg_fill, &overlay_bg_color, 0, 0, 1, OVERLAY_ROW_HEIGHT); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, overlay_bg_fill, &overlay_div_color, 0, OVERLAY_ROW_HEIGHT - 1, 1, 1); + + bitmask = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), 1, 1, 32); + overlay_snowflakes_text_fill = XRenderCreatePicture(VWM_XDISPLAY(vwm), bitmask, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), PictStandardARGB32), CPRepeat, &pa_repeat); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, overlay_snowflakes_text_fill, &overlay_snowflakes_visible_color, 0, 0, 1, 1); + + bitmask = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), 1, 1, 32); + overlay_grapha_fill = XRenderCreatePicture(VWM_XDISPLAY(vwm), bitmask, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), PictStandardARGB32), CPRepeat, &pa_repeat); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, overlay_grapha_fill, &overlay_grapha_color, 0, 0, 1, 1); + + bitmask = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), 1, 1, 32); + overlay_graphb_fill = XRenderCreatePicture(VWM_XDISPLAY(vwm), bitmask, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), PictStandardARGB32), CPRepeat, &pa_repeat); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, overlay_graphb_fill, &overlay_graphb_color, 0, 0, 1, 1); + + bitmask = XCreatePixmap(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), 1, 2, 32); + overlay_finish_fill = XRenderCreatePicture(VWM_XDISPLAY(vwm), bitmask, XRenderFindStandardFormat(VWM_XDISPLAY(vwm), PictStandardARGB32), CPRepeat, &pa_repeat); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, overlay_finish_fill, &overlay_visible_color, 0, 0, 1, 1); + XRenderFillRectangle(VWM_XDISPLAY(vwm), PictOpSrc, overlay_finish_fill, &overlay_trans_color, 0, 1, 1, 1); } @@ -860,7 +860,7 @@ void vwm_overlay_xwin_create(vwm_t *vwm, vwm_xwindow_t *xwin) if (xwin->monitor) return; - if (XGetWindowProperty(vwm->display, xwin->id, vwm->wm_pid_atom, 0, 1, False, XA_CARDINAL, + if (XGetWindowProperty(VWM_XDISPLAY(vwm), xwin->id, vwm->wm_pid_atom, 0, 1, False, XA_CARDINAL, &type, &fmt, &nitems, &nbytes, (unsigned char **)&foo) != Success || !foo) return; pid = *foo; @@ -901,39 +901,39 @@ void vwm_overlay_xwin_compose(vwm_t *vwm, vwm_xwindow_t *xwin) height = vwm_overlay_xwin_composed_height(vwm, xwin); /* fill the overlay picture with the background */ - XRenderComposite(vwm->display, PictOpSrc, overlay_bg_fill, None, xwin->overlay.picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpSrc, overlay_bg_fill, None, xwin->overlay.picture, 0, 0, 0, 0, 0, 0, xwin->attrs.width, height); /* draw the graphs into the overlay through the stencils being maintained by the sample callbacks */ - XRenderComposite(vwm->display, PictOpOver, overlay_grapha_fill, xwin->overlay.grapha_picture, xwin->overlay.picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpOver, overlay_grapha_fill, xwin->overlay.grapha_picture, xwin->overlay.picture, 0, 0, xwin->overlay.phase, 0, 0, 0, xwin->attrs.width, height); - XRenderComposite(vwm->display, PictOpOver, overlay_graphb_fill, xwin->overlay.graphb_picture, xwin->overlay.picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpOver, overlay_graphb_fill, xwin->overlay.graphb_picture, xwin->overlay.picture, 0, 0, xwin->overlay.phase, 0, 0, 0, xwin->attrs.width, height); /* draw the shadow into the overlay picture using a translucent black source drawn through the shadow mask */ - XRenderComposite(vwm->display, PictOpOver, overlay_shadow_fill, xwin->overlay.shadow_picture, xwin->overlay.picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpOver, overlay_shadow_fill, xwin->overlay.shadow_picture, xwin->overlay.picture, 0, 0, 0, 0, 0, 0, xwin->attrs.width, height); /* render overlay text into the overlay picture using a white source drawn through the overlay text as a mask, on top of everything */ - XRenderComposite(vwm->display, PictOpOver, overlay_text_fill, xwin->overlay.text_picture, xwin->overlay.picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpOver, overlay_text_fill, xwin->overlay.text_picture, xwin->overlay.picture, 0, 0, 0, 0, 0, 0, xwin->attrs.width, (xwin->overlay.heirarchy_end * OVERLAY_ROW_HEIGHT)); - XRenderComposite(vwm->display, PictOpOver, overlay_snowflakes_text_fill, xwin->overlay.text_picture, xwin->overlay.picture, + XRenderComposite(VWM_XDISPLAY(vwm), PictOpOver, overlay_snowflakes_text_fill, xwin->overlay.text_picture, xwin->overlay.picture, 0, 0, 0, xwin->overlay.heirarchy_end * OVERLAY_ROW_HEIGHT, 0, xwin->overlay.heirarchy_end * OVERLAY_ROW_HEIGHT, @@ -944,7 +944,7 @@ void vwm_overlay_xwin_compose(vwm_t *vwm, vwm_xwindow_t *xwin) damage.y = xwin->attrs.y + xwin->attrs.border_width; damage.width = xwin->attrs.width; damage.height = height; - region = XFixesCreateRegion(vwm->display, &damage, 1); + region = XFixesCreateRegion(VWM_XDISPLAY(vwm), &damage, 1); vwm_composite_damage_add(vwm, region); } diff --git a/src/screen.c b/src/screen.c index 8fb63a5..4136d95 100644 --- a/src/screen.c +++ b/src/screen.c @@ -58,8 +58,8 @@ const vwm_screen_t * vwm_screen_find(vwm_t *vwm, vwm_screen_rel_t rel, ...) faux.screen_number = 0; faux.x_org = 0; faux.y_org = 0; - faux.width = WidthOfScreen(DefaultScreenOfDisplay(vwm->display)); - faux.height = HeightOfScreen(DefaultScreenOfDisplay(vwm->display)); + faux.width = WidthOfScreen(DefaultScreenOfDisplay(VWM_XDISPLAY(vwm))); + faux.height = HeightOfScreen(DefaultScreenOfDisplay(VWM_XDISPLAY(vwm))); if (!vwm->xinerama_screens) goto _out; @@ -92,7 +92,7 @@ const vwm_screen_t * vwm_screen_find(vwm_t *vwm, vwm_screen_rel_t rel, ...) Window root, child; /* get the pointer coordinates and find which screen it's in */ - XQueryPointer(vwm->display, VWM_XROOT(vwm), &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); + XQueryPointer(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); for_each_screen(scr) { if (root_x >= scr->x_org && root_x < scr->x_org + scr->width && @@ -26,8 +26,6 @@ #include <X11/extensions/Xdamage.h> /* Damage extension, enables receipt of damage events, reports visible regions needing updating (compositing) */ #include <X11/extensions/Xrender.h> /* Render extension, enables use of alpha channels and accelerated rendering of surfaces having alpha (compositing) */ #include <X11/extensions/Xcomposite.h> /* Composite extension, enables off-screen redirection of window rendering (compositing) */ -#include <unistd.h> -#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -48,8 +46,6 @@ #include "xevent.h" #include "xwindow.h" -static vwm_t vwm; - /* Sync */ static int sync_event, sync_error; @@ -60,235 +56,269 @@ static int randr_event, randr_error; /* Compositing */ static int composite_event, composite_error, composite_opcode; -static int errhandler(Display *display, XErrorEvent *err) -{ - /* TODO */ - return 1; -} -int main(int argc, char *argv[]) +static vwm_t * vwm_startup(void) { - int err = 0; - XEvent event; - Cursor pointer; - struct pollfd pfd; - char *console_args[] = {"xterm", "-class", CONSOLE_WM_CLASS, "-e", "/bin/sh", "-c", "screen -D -RR " CONSOLE_SESSION_STRING, NULL}; - char *quit_console_args[] = {"/bin/sh", "-c", "screen -dr " CONSOLE_SESSION_STRING " -X quit", NULL}; - -#define reterr_if(_cond, _fmt, _args...) \ - err++;\ - if (_cond) {\ - VWM_ERROR(_fmt, ##_args);\ - return err;\ - } + Cursor pointer; + char *console_args[] = {"xterm", "-class", CONSOLE_WM_CLASS, "-e", "/bin/sh", "-c", "screen -D -RR " CONSOLE_SESSION_STRING, NULL}; + vwm_t *vwm; - INIT_LIST_HEAD(&vwm.desktops); - INIT_LIST_HEAD(&vwm.desktops_mru); - INIT_LIST_HEAD(&vwm.windows_mru); - INIT_LIST_HEAD(&vwm.xwindows); - - /* open connection with the server */ - reterr_if((vwm.display = XOpenDisplay(NULL)) == NULL, "Cannot open display"); + if (!(vwm = calloc(1, sizeof(vwm_t)))) { + VWM_ERROR("Unable to allocate vwm_t"); + goto _err; + } - /* prevent children from inheriting the X connection */ - reterr_if(fcntl(ConnectionNumber(vwm.display), F_SETFD, FD_CLOEXEC) < 0, "Cannot set FD_CLOEXEC on X connection"); + INIT_LIST_HEAD(&vwm->desktops); + INIT_LIST_HEAD(&vwm->desktops_mru); + INIT_LIST_HEAD(&vwm->windows_mru); + INIT_LIST_HEAD(&vwm->xwindows); - /* get our scheduling priority, clients are launched with a priority LAUNCHED_RELATIVE_PRIORITY nicer than this */ - reterr_if((vwm.priority = getpriority(PRIO_PROCESS, getpid())) == -1, "Cannot get scheduling priority"); + if (!(vwm->xserver = vwm_xserver_open())) { + VWM_ERROR("Failed to open xserver"); + goto _err_free; + } - XSetErrorHandler(errhandler); + /* query the needed X extensions */ + if (!XQueryExtension(VWM_XDISPLAY(vwm), COMPOSITE_NAME, &composite_opcode, &composite_event, &composite_error)) { + VWM_ERROR("No composite extension available"); + goto _err_xclose; + } - vwm.screen_num = DefaultScreen(vwm.display); + if (!XDamageQueryExtension(VWM_XDISPLAY(vwm), &vwm->damage_event, &vwm->damage_error)) { + VWM_ERROR("No damage extension available"); + goto _err_xclose; + } - /* query the needed X extensions */ - reterr_if(!XQueryExtension (vwm.display, COMPOSITE_NAME, &composite_opcode, &composite_event, &composite_error), "No composite extension available"); - reterr_if(!XDamageQueryExtension(vwm.display, &vwm.damage_event, &vwm.damage_error), "No damage extension available"); - if (XSyncQueryExtension(vwm.display, &sync_event, &sync_error)) { + if (XSyncQueryExtension(VWM_XDISPLAY(vwm), &sync_event, &sync_error)) { /* set the window manager to the maximum X client priority */ - XSyncSetPriority(vwm.display, VWM_XROOT(&vwm), 0x7fffffff); + XSyncSetPriority(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), 0x7fffffff); } - if (XineramaQueryExtension(vwm.display, &xinerama_event, &xinerama_error)) { - vwm.xinerama_screens = XineramaQueryScreens(vwm.display, &vwm.xinerama_screens_cnt); + if (XineramaQueryExtension(VWM_XDISPLAY(vwm), &xinerama_event, &xinerama_error)) { + vwm->xinerama_screens = XineramaQueryScreens(VWM_XDISPLAY(vwm), &vwm->xinerama_screens_cnt); } - if (XRRQueryExtension(vwm.display, &randr_event, &randr_error)) { - XRRSelectInput(vwm.display, VWM_XROOT(&vwm), RRScreenChangeNotifyMask); + if (XRRQueryExtension(VWM_XDISPLAY(vwm), &randr_event, &randr_error)) { + XRRSelectInput(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), RRScreenChangeNotifyMask); } - /* allocate colors, I make assumptions about the X server's color capabilities since I'll only use this on modern-ish computers... */ - vwm.cmap = DefaultColormap(vwm.display, vwm.screen_num); + /* get our scheduling priority, clients are launched with a priority LAUNCHED_RELATIVE_PRIORITY nicer than this */ + if ((vwm->priority = getpriority(PRIO_PROCESS, getpid())) == -1) { + VWM_ERROR("Cannot get scheduling priority"); + goto _err_xclose; + } + + vwm->wm_delete_atom = XInternAtom(VWM_XDISPLAY(vwm), "WM_DELETE_WINDOW", False); + vwm->wm_protocols_atom = XInternAtom(VWM_XDISPLAY(vwm), "WM_PROTOCOLS", False); + vwm->wm_pid_atom = XInternAtom(VWM_XDISPLAY(vwm), "_NET_WM_PID", False); + /* allocate colors, I make assumptions about the X server's color capabilities since I'll only use this on modern-ish computers... */ #define color(_sym, _str) \ - XAllocNamedColor(vwm.display, vwm.cmap, _str, &vwm.colors._sym ## _color, &vwm.colors._sym ## _color); + XAllocNamedColor(VWM_XDISPLAY(vwm), VWM_XCMAP(vwm), _str, &vwm->colors._sym ## _color, &vwm->colors._sym ## _color); #include "colors.def" #undef color - vwm.wm_delete_atom = XInternAtom(vwm.display, "WM_DELETE_WINDOW", False); - vwm.wm_protocols_atom = XInternAtom(vwm.display, "WM_PROTOCOLS", False); - vwm.wm_pid_atom = XInternAtom(vwm.display, "_NET_WM_PID", False); - - XSelectInput(vwm.display, VWM_XROOT(&vwm), + XSelectInput(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), PropertyChangeMask | SubstructureNotifyMask | SubstructureRedirectMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask); - XGrabKey(vwm.display, AnyKey, WM_GRAB_MODIFIER, VWM_XROOT(&vwm), False, GrabModeAsync, GrabModeAsync); + XGrabKey(VWM_XDISPLAY(vwm), AnyKey, WM_GRAB_MODIFIER, VWM_XROOT(vwm), False, GrabModeAsync, GrabModeAsync); - XFlush(vwm.display); + XFlush(VWM_XDISPLAY(vwm)); - XSetInputFocus(vwm.display, VWM_XROOT(&vwm), RevertToPointerRoot, CurrentTime); + XSetInputFocus(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), RevertToPointerRoot, CurrentTime); /* create initial virtual desktop */ - vwm_desktop_focus(&vwm, vwm_desktop_create(&vwm, NULL)); - vwm_desktop_mru(&vwm, vwm.focused_desktop); + vwm_desktop_focus(vwm, vwm_desktop_create(vwm, NULL)); + vwm_desktop_mru(vwm, vwm->focused_desktop); /* manage all preexisting windows */ - vwm_xwin_create_existing(&vwm); + vwm_xwin_create_existing(vwm); - /* create GC for logo drawing and window rubber-banding */ - vwm.gc = XCreateGC(vwm.display, VWM_XROOT(&vwm), 0, NULL); - XSetSubwindowMode(vwm.display, vwm.gc, IncludeInferiors); - XSetFunction(vwm.display, vwm.gc, GXxor); + /* setup GC for logo drawing and window rubber-banding */ + XSetSubwindowMode(VWM_XDISPLAY(vwm), VWM_XGC(vwm), IncludeInferiors); + XSetFunction(VWM_XDISPLAY(vwm), VWM_XGC(vwm), GXxor); /* launch the console here so it's likely ready by the time the logo animation finishes (there's no need to synchronize with it currently) */ - vwm_launch(&vwm, console_args, VWM_LAUNCH_MODE_BG); + vwm_launch(vwm, console_args, VWM_LAUNCH_MODE_BG); /* first the logo color is the foreground */ - XSetForeground(vwm.display, vwm.gc, vwm.colors.logo_color.pixel); - vwm_draw_logo(&vwm); + XSetForeground(VWM_XDISPLAY(vwm), VWM_XGC(vwm), vwm->colors.logo_color.pixel); + vwm_draw_logo(vwm); /* change to the rubber-banding foreground color */ - XSetForeground(vwm.display, vwm.gc, vwm.colors.rubberband_color.pixel); + XSetForeground(VWM_XDISPLAY(vwm), VWM_XGC(vwm), vwm->colors.rubberband_color.pixel); - XClearWindow(vwm.display, VWM_XROOT(&vwm)); + XClearWindow(VWM_XDISPLAY(vwm), VWM_XROOT(vwm)); /* set the pointer */ - pointer = XCreateFontCursor(vwm.display, XC_X_cursor); - XDefineCursor(vwm.display, VWM_XROOT(&vwm), pointer); + pointer = XCreateFontCursor(VWM_XDISPLAY(vwm), XC_X_cursor); + XDefineCursor(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), pointer); + + return vwm; + + +_err_xclose: + vwm_xserver_close(vwm->xserver); + +_err_free: + free(vwm); + +_err: + return NULL; +} + + +void vwm_shutdown(vwm_t *vwm) +{ + char *quit_console_args[] = {"/bin/sh", "-c", "screen -dr " CONSOLE_SESSION_STRING " -X quit", NULL}; + + vwm_launch(vwm, quit_console_args, VWM_LAUNCH_MODE_FG); + vwm_xserver_close(vwm->xserver); + /* TODO there's more shit to cleanup here, but we're exiting anyways. */ + free(vwm); +} + + +void vwm_process_event(vwm_t *vwm) +{ + XEvent event; + + XNextEvent(VWM_XDISPLAY(vwm), &event); + switch (event.type) { + case KeyPress: + VWM_TRACE("keypress"); + vwm_xevent_handle_key_press(vwm, &event.xkey); + break; + + case KeyRelease: + VWM_TRACE("keyrelease"); + vwm_xevent_handle_key_release(vwm, &event.xkey); + break; + + case ButtonPress: + VWM_TRACE("buttonpresss"); + vwm_xevent_handle_button_press(vwm, &event.xbutton); + break; + + case MotionNotify: + //VWM_TRACE("motionnotify"); + vwm_xevent_handle_motion_notify(vwm, &event.xmotion); + break; + + case ButtonRelease: + VWM_TRACE("buttonrelease"); + vwm_xevent_handle_button_release(vwm, &event.xbutton); + break; + + case CreateNotify: + VWM_TRACE("createnotify"); + vwm_xevent_handle_create_notify(vwm, &event.xcreatewindow); + break; + + case DestroyNotify: + VWM_TRACE("destroynotify"); + vwm_xevent_handle_destroy_notify(vwm, &event.xdestroywindow); + break; + + case ConfigureRequest: + VWM_TRACE("configurerequest"); + vwm_xevent_handle_configure_request(vwm, &event.xconfigurerequest); + break; + + case ConfigureNotify: + VWM_TRACE("configurenotify"); + vwm_xevent_handle_configure_notify(vwm, &event.xconfigure); + break; + + case UnmapNotify: + VWM_TRACE("unmapnotify"); + vwm_xevent_handle_unmap_notify(vwm, &event.xunmap); + break; + + case MapNotify: + VWM_TRACE("mapnotify"); + vwm_xevent_handle_map_notify(vwm, &event.xmap); + break; + + case MapRequest: + VWM_TRACE("maprequest"); + vwm_xevent_handle_map_request(vwm, &event.xmaprequest); + break; + + case PropertyNotify: + VWM_TRACE("property notify"); + vwm_xevent_handle_property_notify(vwm, &event.xproperty); + break; + + case MappingNotify: + VWM_TRACE("mapping notify"); + vwm_xevent_handle_mapping_notify(vwm, &event.xmapping); + break; + + case Expose: + VWM_TRACE("expose"); + break; + + case GravityNotify: + VWM_TRACE("gravitynotify"); + break; + + case ReparentNotify: + VWM_TRACE("reparentnotify"); + break; + + default: + if (event.type == randr_event + RRScreenChangeNotify) { + VWM_TRACE("rrscreenchangenotify"); + if (vwm->xinerama_screens) XFree(vwm->xinerama_screens); + vwm->xinerama_screens = XineramaQueryScreens(VWM_XDISPLAY(vwm), &vwm->xinerama_screens_cnt); + + vwm_composite_invalidate_root(vwm); + } else if (event.type == vwm->damage_event + XDamageNotify) { + //VWM_TRACE("damagenotify"); + vwm_composite_damage_event(vwm, (XDamageNotifyEvent *)&event); + } else { + VWM_ERROR("Unhandled X op %i", event.type); + } + break; + } +} + + +int main(int argc, char *argv[]) +{ + vwm_t *vwm; + struct pollfd pfd; + + if (!(vwm = vwm_startup())) { + VWM_ERROR("Unable to startup vwm"); + goto _err; + } pfd.events = POLLIN; pfd.revents = 0; - pfd.fd = ConnectionNumber(vwm.display); + pfd.fd = ConnectionNumber(VWM_XDISPLAY(vwm)); - while (!vwm.done) { + while (!vwm->done) { do { int delay; - vwm_overlay_update(&vwm, &delay); - XFlush(vwm.display); + vwm_overlay_update(vwm, &delay); + XFlush(VWM_XDISPLAY(vwm)); - if (!XPending(vwm.display)) { + if (!XPending(VWM_XDISPLAY(vwm))) { if (poll(&pfd, 1, delay) == 0) break; } - XNextEvent(vwm.display, &event); - switch (event.type) { - case KeyPress: - VWM_TRACE("keypress"); - vwm_xevent_handle_key_press(&vwm, &event.xkey); - break; - - case KeyRelease: - VWM_TRACE("keyrelease"); - vwm_xevent_handle_key_release(&vwm, &event.xkey); - break; - - case ButtonPress: - VWM_TRACE("buttonpresss"); - vwm_xevent_handle_button_press(&vwm, &event.xbutton); - break; - - case MotionNotify: - //VWM_TRACE("motionnotify"); - vwm_xevent_handle_motion_notify(&vwm, &event.xmotion); - break; - - case ButtonRelease: - VWM_TRACE("buttonrelease"); - vwm_xevent_handle_button_release(&vwm, &event.xbutton); - break; - - case CreateNotify: - VWM_TRACE("createnotify"); - vwm_xevent_handle_create_notify(&vwm, &event.xcreatewindow); - break; - - case DestroyNotify: - VWM_TRACE("destroynotify"); - vwm_xevent_handle_destroy_notify(&vwm, &event.xdestroywindow); - break; - - case ConfigureRequest: - VWM_TRACE("configurerequest"); - vwm_xevent_handle_configure_request(&vwm, &event.xconfigurerequest); - break; - - case ConfigureNotify: - VWM_TRACE("configurenotify"); - vwm_xevent_handle_configure_notify(&vwm, &event.xconfigure); - break; - - case UnmapNotify: - VWM_TRACE("unmapnotify"); - vwm_xevent_handle_unmap_notify(&vwm, &event.xunmap); - break; - - case MapNotify: - VWM_TRACE("mapnotify"); - vwm_xevent_handle_map_notify(&vwm, &event.xmap); - break; - - case MapRequest: - VWM_TRACE("maprequest"); - vwm_xevent_handle_map_request(&vwm, &event.xmaprequest); - break; - - case PropertyNotify: - VWM_TRACE("property notify"); - vwm_xevent_handle_property_notify(&vwm, &event.xproperty); - break; - - case MappingNotify: - VWM_TRACE("mapping notify"); - vwm_xevent_handle_mapping_notify(&vwm, &event.xmapping); - break; - - case Expose: - VWM_TRACE("expose"); - break; - - case GravityNotify: - VWM_TRACE("gravitynotify"); - break; - - case ReparentNotify: - VWM_TRACE("reparentnotify"); - break; - - default: - if (event.type == randr_event + RRScreenChangeNotify) { - VWM_TRACE("rrscreenchangenotify"); - if (vwm.xinerama_screens) XFree(vwm.xinerama_screens); - vwm.xinerama_screens = XineramaQueryScreens(vwm.display, &vwm.xinerama_screens_cnt); - - vwm_composite_invalidate_root(&vwm); - } else if (event.type == vwm.damage_event + XDamageNotify) { - //VWM_TRACE("damagenotify"); - vwm_composite_damage_event(&vwm, (XDamageNotifyEvent *)&event); - } else { - VWM_ERROR("Unhandled X op %i", event.type); - } - break; - } - } while (QLength(vwm.display)); + vwm_process_event(vwm); + } while (QLength(VWM_XDISPLAY(vwm))); - vwm_composite_paint_all(&vwm); + vwm_composite_paint_all(vwm); } - /* tear down console */ - vwm_launch(&vwm, quit_console_args, VWM_LAUNCH_MODE_FG); + vwm_shutdown(vwm); - /* close connection to server */ - XFlush(vwm.display); - XCloseDisplay(vwm.display); + return EXIT_SUCCESS; - return 0; +_err: + return EXIT_FAILURE; } @@ -9,6 +9,7 @@ #include "context.h" #include "list.h" #include "util.h" +#include "xserver.h" #define WINDOW_BORDER_WIDTH 1 #define WM_GRAB_MODIFIER Mod1Mask /* the modifier for invoking vwm's controls */ @@ -21,15 +22,21 @@ #define CONSOLE_WM_CLASS "VWMConsoleXTerm" /* the class we specify to the "console" xterm */ #define CONSOLE_SESSION_STRING "_vwm_console.$DISPLAY" /* the unique console screen session identifier */ +#define VWM_XCMAP(_vwm) (_vwm)->xserver->cmap +#define VWM_XDISPLAY(_vwm) (_vwm)->xserver->display +#define VWM_XGC(_vwm) (_vwm)->xserver->gc +#define VWM_XSCREENNUM(_vwm) (_vwm)->xserver->screen_num +#define VWM_XROOT(_vwm) XSERVER_XROOT((_vwm)->xserver) +#define VWM_XVISUAL(_vwm) XSERVER_XVISUAL((_vwm)->xserver) +#define VWM_XDEPTH(_vwm) XSERVER_XDEPTH((_vwm)->xserver) typedef struct _vwm_window_t vwm_window_t; typedef struct _vwm_desktop_t vwm_desktop_t; typedef struct _vwm_t { - Display *display; - Colormap cmap; - int screen_num; - GC gc; + vwm_xserver_t *xserver; /* global xserver instance */ + + /* extra X stuff needed by vwm */ Atom wm_delete_atom; Atom wm_protocols_atom; Atom wm_pid_atom; diff --git a/src/window.c b/src/window.c index e28330a..fa62841 100644 --- a/src/window.c +++ b/src/window.c @@ -36,7 +36,7 @@ void vwm_win_unmap(vwm_t *vwm, vwm_window_t *vwin) } VWM_TRACE("Unmapping \"%s\"", vwin->xwindow->name); vwin->unmapping = 1; - XUnmapWindow(vwm->display, vwin->xwindow->id); + XUnmapWindow(VWM_XDISPLAY(vwm), vwin->xwindow->id); } @@ -49,7 +49,7 @@ void vwm_win_map(vwm_t *vwm, vwm_window_t *vwin) } VWM_TRACE("Mapping \"%s\"", vwin->xwindow->name); vwin->mapping = 1; - XMapWindow(vwm->display, vwin->xwindow->id); + XMapWindow(VWM_XDISPLAY(vwm), vwin->xwindow->id); } @@ -198,7 +198,7 @@ void vwm_win_autoconf(vwm_t *vwm, vwm_window_t *vwin, vwm_screen_rel_t rel, vwm_ } va_end(ap); - XConfigureWindow(vwm->display, vwin->xwindow->id, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &changes); + XConfigureWindow(VWM_XDISPLAY(vwm), vwin->xwindow->id, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &changes); vwin->autoconfigured = conf; } @@ -211,23 +211,23 @@ void vwm_win_focus(vwm_t *vwm, vwm_window_t *vwin) if (vwm_xwin_is_mapped(vwm, vwin->xwindow)) { /* if vwin is mapped give it the input focus */ - XSetInputFocus(vwm->display, vwin->xwindow->id, RevertToPointerRoot, CurrentTime); + XSetInputFocus(VWM_XDISPLAY(vwm), vwin->xwindow->id, RevertToPointerRoot, CurrentTime); } /* update the border color accordingly */ if (vwin->shelved) { /* set the border of the newly focused window to the shelved color */ - XSetWindowBorder(vwm->display, vwin->xwindow->id, vwin == vwm->console ? vwm->colors.shelved_console_border_color.pixel : vwm->colors.shelved_window_border_color.pixel); + XSetWindowBorder(VWM_XDISPLAY(vwm), vwin->xwindow->id, vwin == vwm->console ? vwm->colors.shelved_console_border_color.pixel : vwm->colors.shelved_window_border_color.pixel); /* fullscreen windows in the shelf when focused, since we don't intend to overlap there */ vwm_win_autoconf(vwm, vwin, VWM_SCREEN_REL_POINTER, VWM_WIN_AUTOCONF_FULL); /* XXX TODO: for now the shelf follows the pointer, it's simple. */ } else { if (vwin->desktop->focused_window) { /* set the border of the previously focused window on the same desktop to the unfocused color */ - XSetWindowBorder(vwm->display, vwin->desktop->focused_window->xwindow->id, vwm->colors.unfocused_window_border_color.pixel); + XSetWindowBorder(VWM_XDISPLAY(vwm), vwin->desktop->focused_window->xwindow->id, vwm->colors.unfocused_window_border_color.pixel); } /* set the border of the newly focused window to the focused color */ - XSetWindowBorder(vwm->display, vwin->xwindow->id, vwm->colors.focused_window_border_color.pixel); + XSetWindowBorder(VWM_XDISPLAY(vwm), vwin->xwindow->id, vwm->colors.focused_window_border_color.pixel); /* persist this on a per-desktop basis so it can be restored on desktop switches */ vwin->desktop->focused_window = vwin; @@ -282,7 +282,7 @@ _retry: /* TODO FIXME: this makes assumptions about the shelf being focused calling unmap/map directly.. */ vwm_win_unmap(vwm, vwm->focused_shelf); - XFlush(vwm->display); + XFlush(VWM_XDISPLAY(vwm)); vwm_win_map(vwm, next); vwm->focused_shelf = next; @@ -292,7 +292,7 @@ _retry: if (next != next->desktop->focused_window) { /* focus the changed window */ vwm_win_focus(vwm, next); - XRaiseWindow(vwm->display, next->xwindow->id); + XRaiseWindow(VWM_XDISPLAY(vwm), next->xwindow->id); } } @@ -389,17 +389,17 @@ vwm_window_t * vwm_win_manage_xwin(vwm_t *vwm, vwm_xwindow_t *xwin) goto _fail; } - XUngrabButton(vwm->display, AnyButton, AnyModifier, xwin->id); - XGrabButton(vwm->display, AnyButton, WM_GRAB_MODIFIER, xwin->id, False, (PointerMotionMask | ButtonPressMask | ButtonReleaseMask), GrabModeAsync, GrabModeAsync, None, None); - XGrabKey(vwm->display, AnyKey, WM_GRAB_MODIFIER, xwin->id, False, GrabModeAsync, GrabModeAsync); - XSetWindowBorder(vwm->display, xwin->id, vwm->colors.unfocused_window_border_color.pixel); + XUngrabButton(VWM_XDISPLAY(vwm), AnyButton, AnyModifier, xwin->id); + XGrabButton(VWM_XDISPLAY(vwm), AnyButton, WM_GRAB_MODIFIER, xwin->id, False, (PointerMotionMask | ButtonPressMask | ButtonReleaseMask), GrabModeAsync, GrabModeAsync, None, None); + XGrabKey(VWM_XDISPLAY(vwm), AnyKey, WM_GRAB_MODIFIER, xwin->id, False, GrabModeAsync, GrabModeAsync); + XSetWindowBorder(VWM_XDISPLAY(vwm), xwin->id, vwm->colors.unfocused_window_border_color.pixel); vwin->hints = XAllocSizeHints(); if (!vwin->hints) { VWM_PERROR("Failed to allocate WM hints"); goto _fail; } - XGetWMNormalHints(vwm->display, xwin->id, vwin->hints, &vwin->hints_supplied); + XGetWMNormalHints(VWM_XDISPLAY(vwm), xwin->id, vwin->hints, &vwin->hints_supplied); xwin->managed = vwin; vwin->xwindow = xwin; @@ -434,7 +434,7 @@ vwm_window_t * vwm_win_manage_xwin(vwm_t *vwm, vwm_xwindow_t *xwin) } /* always raise newly managed windows so we know about them. */ - XRaiseWindow(vwm->display, xwin->id); + XRaiseWindow(VWM_XDISPLAY(vwm), xwin->id); /* if the desktop has no focused window yet, automatically focus the newly managed one, provided we're on the desktop context */ if (!vwm->focused_desktop->focused_window && vwm->focused_context == VWM_CONTEXT_DESKTOP) { @@ -464,5 +464,5 @@ void vwm_win_migrate(vwm_t *vwm, vwm_window_t *vwin, vwm_desktop_t *desktop) vwm_win_focus(vwm, vwin); /* focus the window so borders get updated */ vwm_win_mru(vwm, vwin); /* TODO: is this right? shouldn't the Mod1 release be what's responsible for this? I migrate so infrequently it probably doesn't matter */ - XRaiseWindow(vwm->display, vwin->xwindow->id); /* ensure the window is raised */ + XRaiseWindow(VWM_XDISPLAY(vwm), vwin->xwindow->id); /* ensure the window is raised */ } diff --git a/src/xevent.c b/src/xevent.c index 3af104d..97c4930 100644 --- a/src/xevent.c +++ b/src/xevent.c @@ -97,7 +97,7 @@ void vwm_xevent_handle_configure_request(vwm_t *vwm, XConfigureRequestEvent *ev) change_mask &= ~CWBorderWidth; } - XConfigureWindow(vwm->display, ev->window, change_mask, &changes); + XConfigureWindow(VWM_XDISPLAY(vwm), ev->window, change_mask, &changes); } @@ -108,7 +108,7 @@ void vwm_xevent_handle_configure_notify(vwm_t *vwm, XConfigureEvent *ev) if ((xwin = vwm_xwin_lookup(vwm, ev->window))) { XWindowAttributes attrs; vwm_xwin_restack(vwm, xwin, ev->above); - XGetWindowAttributes(vwm->display, ev->window, &attrs); + XGetWindowAttributes(VWM_XDISPLAY(vwm), ev->window, &attrs); vwm_composite_handle_configure(vwm, xwin, &attrs); VWM_TRACE("pre x=%i y=%i w=%i h=%i\n", xwin->attrs.x, xwin->attrs.y, xwin->attrs.width, xwin->attrs.height); xwin->attrs = attrs; @@ -191,7 +191,7 @@ void vwm_xevent_handle_map_request(vwm_t *vwm, XMapRequestEvent *ev) /* figure out if the window is the console */ if ((classhint = XAllocClassHint())) { - if (XGetClassHint(vwm->display, ev->window, classhint) && !strcmp(classhint->res_class, CONSOLE_WM_CLASS)) { + if (XGetClassHint(VWM_XDISPLAY(vwm), ev->window, classhint) && !strcmp(classhint->res_class, CONSOLE_WM_CLASS)) { vwm->console = vwin; vwm_win_shelve(vwm, vwin); vwm_win_autoconf(vwm, vwin, VWM_SCREEN_REL_XWIN, VWM_WIN_AUTOCONF_FULL); @@ -231,8 +231,8 @@ void vwm_xevent_handle_map_request(vwm_t *vwm, XMapRequestEvent *ev) } /* XXX TODO: does this belong here? */ - XGetWMNormalHints(vwm->display, ev->window, vwin->hints, &vwin->hints_supplied); - XGetWindowAttributes(vwm->display, ev->window, &attrs); + XGetWMNormalHints(VWM_XDISPLAY(vwm), ev->window, vwin->hints, &vwin->hints_supplied); + XGetWindowAttributes(VWM_XDISPLAY(vwm), ev->window, &attrs); /* if the window size is precisely the screen size then directly "allscreen" the window right here */ @@ -250,14 +250,14 @@ void vwm_xevent_handle_map_request(vwm_t *vwm, XMapRequestEvent *ev) vwin->client.height = attrs.height; vwin->client.width = attrs.width; - XConfigureWindow(vwm->display, ev->window, changes_mask, &changes); + XConfigureWindow(VWM_XDISPLAY(vwm), ev->window, changes_mask, &changes); } if (domap) { - XMapWindow(vwm->display, ev->window); + XMapWindow(VWM_XDISPLAY(vwm), ev->window); if (vwin && vwin->desktop->focused_window == vwin) { - XSync(vwm->display, False); - XSetInputFocus(vwm->display, vwin->xwindow->id, RevertToPointerRoot, CurrentTime); + XSync(VWM_XDISPLAY(vwm), False); + XSetInputFocus(VWM_XDISPLAY(vwm), vwin->xwindow->id, RevertToPointerRoot, CurrentTime); } } } diff --git a/src/xwindow.c b/src/xwindow.c index 24ed1df..76d758e 100644 --- a/src/xwindow.c +++ b/src/xwindow.c @@ -42,7 +42,7 @@ void vwm_xwin_message(vwm_t *vwm, vwm_xwindow_t *xwin, Atom type, long foo) event.xclient.data.l[0] = foo; event.xclient.data.l[1] = CurrentTime; /* XXX TODO: is CurrentTime actually correct to use for this purpose? */ - XSendEvent(vwm->display, xwin->id, False, 0, &event); + XSendEvent(VWM_XDISPLAY(vwm), xwin->id, False, 0, &event); } @@ -105,12 +105,12 @@ vwm_xwindow_t * vwm_xwin_create(vwm_t *vwm, Window win, vwm_grab_mode_t grabbed) /* prevent races */ if (!grabbed) { - XGrabServer(vwm->display); - XSync(vwm->display, False); + XGrabServer(VWM_XDISPLAY(vwm)); + XSync(VWM_XDISPLAY(vwm), False); } /* verify the window still exists */ - if (!XGetWindowAttributes(vwm->display, win, &attrs)) goto _out_grabbed; + if (!XGetWindowAttributes(VWM_XDISPLAY(vwm), win, &attrs)) goto _out_grabbed; /* don't create InputOnly windows */ if (attrs.class == InputOnly) goto _out_grabbed; @@ -124,7 +124,7 @@ vwm_xwindow_t * vwm_xwin_create(vwm_t *vwm, Window win, vwm_grab_mode_t grabbed) xwin->attrs = attrs; xwin->managed = NULL; xwin->name = NULL; - XFetchName(vwm->display, win, &xwin->name); + XFetchName(VWM_XDISPLAY(vwm), win, &xwin->name); xwin->monitor = NULL; xwin->overlay.width = xwin->overlay.height = xwin->overlay.phase = 0; @@ -132,7 +132,7 @@ vwm_xwindow_t * vwm_xwin_create(vwm_t *vwm, Window win, vwm_grab_mode_t grabbed) /* This is so we get the PropertyNotify event and can get the pid when it's set post-create, * with my _NET_WM_PID patch the property is immediately available */ - XSelectInput(vwm->display, win, PropertyChangeMask); + XSelectInput(VWM_XDISPLAY(vwm), win, PropertyChangeMask); /* we must track the mapped-by-client state of the window independent of managed vs. unmanaged because * in the case of override_redirect windows they may be unmapped (invisible) or mapped (visible) like menus without being managed. @@ -150,7 +150,7 @@ vwm_xwindow_t * vwm_xwin_create(vwm_t *vwm, Window win, vwm_grab_mode_t grabbed) if (xwin->mapped) vwm_win_manage_xwin(vwm, xwin); #endif _out_grabbed: - if (!grabbed) XUngrabServer(vwm->display); + if (!grabbed) XUngrabServer(VWM_XDISPLAY(vwm)); return xwin; } @@ -160,8 +160,8 @@ _out_grabbed: /* if the window is also managed it will be unmanaged first */ void vwm_xwin_destroy(vwm_t *vwm, vwm_xwindow_t *xwin) { - XGrabServer(vwm->display); - XSync(vwm->display, False); + XGrabServer(VWM_XDISPLAY(vwm)); + XSync(VWM_XDISPLAY(vwm), False); if (xwin->managed) vwm_win_unmanage(vwm, xwin->managed); @@ -174,7 +174,7 @@ void vwm_xwin_destroy(vwm_t *vwm, vwm_xwindow_t *xwin) free(xwin); - XUngrabServer(vwm->display); + XUngrabServer(VWM_XDISPLAY(vwm)); } @@ -223,9 +223,9 @@ int vwm_xwin_create_existing(vwm_t *vwm) unsigned int n_children, i; /* TODO FIXME I don't think this is right anymore, not since we went compositing and split managed vs. bare xwindows... */ - XGrabServer(vwm->display); - XSync(vwm->display, False); - XQueryTree(vwm->display, VWM_XROOT(vwm), &root, &parent, &children, &n_children); + XGrabServer(VWM_XDISPLAY(vwm)); + XSync(VWM_XDISPLAY(vwm), False); + XQueryTree(VWM_XDISPLAY(vwm), VWM_XROOT(vwm), &root, &parent, &children, &n_children); for (i = 0; i < n_children; i++) { if (children[i] == None) continue; @@ -233,14 +233,14 @@ int vwm_xwin_create_existing(vwm_t *vwm) if ((vwm_xwin_create(vwm, children[i], VWM_GRABBED) == NULL)) goto _fail_grabbed; } - XUngrabServer(vwm->display); + XUngrabServer(VWM_XDISPLAY(vwm)); if (children) XFree(children); return 1; _fail_grabbed: - XUngrabServer(vwm->display); + XUngrabServer(VWM_XDISPLAY(vwm)); if (children) XFree(children); |