diff options
author | Dennis Kasprzyk <onestone@opencompositing.org> | 2008-08-06 14:39:07 +0200 |
---|---|---|
committer | Dennis Kasprzyk <onestone@opencompositing.org> | 2008-08-06 14:39:07 +0200 |
commit | 9c76f36894f1f825aa01f519e2b364b979c32a26 (patch) | |
tree | eec49bb1794ee6570acb47a30a9ddc695198e57e | |
parent | 0e942665257980878d6271cbcad4647d04204093 (diff) | |
download | compiz-with-glib-mainloop-9c76f36894f1f825aa01f519e2b364b979c32a26.tar.gz compiz-with-glib-mainloop-9c76f36894f1f825aa01f519e2b364b979c32a26.tar.bz2 |
Conversion ob main classes to C++.
-rw-r--r-- | include/compcore.h | 158 | ||||
-rw-r--r-- | include/compdisplay.h | 427 | ||||
-rw-r--r-- | include/compiz-core.h | 1771 | ||||
-rw-r--r-- | include/compiz.h | 35 | ||||
-rw-r--r-- | include/compobject.h | 13 | ||||
-rw-r--r-- | include/compplugin.h (renamed from include/compiz-plugin.h) | 58 | ||||
-rw-r--r-- | include/compscreen.h | 554 | ||||
-rw-r--r-- | include/compwindow.h | 563 | ||||
-rw-r--r-- | metadata/core.xml.in | 31 | ||||
-rw-r--r-- | plugins/Makefile.am | 19 | ||||
-rw-r--r-- | plugins/move.cpp | 588 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/core.cpp | 599 | ||||
-rw-r--r-- | src/cursor.cpp | 36 | ||||
-rw-r--r-- | src/display.cpp | 3903 | ||||
-rw-r--r-- | src/event.cpp | 1465 | ||||
-rw-r--r-- | src/fragment.cpp | 40 | ||||
-rw-r--r-- | src/main.cpp | 66 | ||||
-rw-r--r-- | src/match.cpp | 43 | ||||
-rw-r--r-- | src/metadata.cpp | 20 | ||||
-rw-r--r-- | src/option.cpp | 4 | ||||
-rw-r--r-- | src/paint.cpp | 521 | ||||
-rw-r--r-- | src/plugin.cpp | 178 | ||||
-rw-r--r-- | src/privatecore.h | 42 | ||||
-rw-r--r-- | src/privatedisplay.h | 138 | ||||
-rw-r--r-- | src/privatescreen.h | 251 | ||||
-rw-r--r-- | src/privatewindow.h | 269 | ||||
-rw-r--r-- | src/screen.cpp | 4023 | ||||
-rw-r--r-- | src/session.cpp | 22 | ||||
-rw-r--r-- | src/texture.cpp | 127 | ||||
-rw-r--r-- | src/window.cpp | 5012 |
31 files changed, 11303 insertions, 9675 deletions
diff --git a/include/compcore.h b/include/compcore.h new file mode 100644 index 0000000..123d7f4 --- /dev/null +++ b/include/compcore.h @@ -0,0 +1,158 @@ +#ifndef _COMPCORE_H +#define _COMPCORE_H + +#include <list> +#include "wrapable.h" + +class PrivateCore; +class CompCore; +class CompDisplay; + +#define NOTIFY_CREATE_MASK (1 << 0) +#define NOTIFY_DELETE_MASK (1 << 1) +#define NOTIFY_MOVE_MASK (1 << 2) +#define NOTIFY_MODIFY_MASK (1 << 3) + +typedef void (*FileWatchCallBackProc) (const char *name, + void *closure); + +typedef int CompFileWatchHandle; + +typedef struct _CompFileWatch { + char *path; + int mask; + FileWatchCallBackProc callBack; + void *closure; + CompFileWatchHandle handle; +} CompFileWatch; + +typedef struct _CompTimeout { + int minTime; + int maxTime; + int minLeft; + int maxLeft; + CallBackProc callBack; + void *closure; + CompTimeoutHandle handle; +} CompTimeout; + +typedef struct _CompWatchFd { + int fd; + CallBackProc callBack; + void *closure; + CompWatchFdHandle handle; +} CompWatchFd; + +int +allocCoreObjectPrivateIndex (CompObject *parent); + +void +freeCoreObjectPrivateIndex (CompObject *parent, + int index); + +CompBool +forEachCoreObject (CompObject *parent, + ObjectCallBackProc proc, + void *closure); + +char * +nameCoreObject (CompObject *object); + +CompObject * +findCoreObject (CompObject *parent, + const char *name); + +int +allocateCorePrivateIndex (void); + +void +freeCorePrivateIndex (int index); + + +class CoreInterface : public WrapableInterface<CompCore> { + public: + CoreInterface (); + + WRAPABLE_DEF(void, fileWatchAdded, CompFileWatch *) + WRAPABLE_DEF(void, fileWatchRemoved, CompFileWatch *) + + WRAPABLE_DEF(bool, initPluginForObject, CompPlugin *, CompObject *) + WRAPABLE_DEF(void, finiPluginForObject, CompPlugin *, CompObject *) + + WRAPABLE_DEF(bool, setOptionForPlugin, CompObject *, const char *, const char *, CompOptionValue *) + + WRAPABLE_DEF(void, objectAdd, CompObject *, CompObject *) + WRAPABLE_DEF(void, objectRemove, CompObject *, CompObject *) + + WRAPABLE_DEF(void, sessionEvent, CompSessionEvent, CompOption *, unsigned int) +}; + +class CompCore : public WrapableHandler<CoreInterface>, public CompObject { + + // functions + public: + CompCore (); + ~CompCore (); + + bool + init (); + + bool + addDisplay (const char *name); + + void + removeDisplay (CompDisplay *); + + void + eventLoop (); + + CompDisplay * + displays(); + + CompFileWatchHandle + addFileWatch (const char *path, + int mask, + FileWatchCallBackProc callBack, + void *closure); + + void + removeFileWatch (CompFileWatchHandle handle); + + CompTimeoutHandle + addTimeout (int minTime, + int maxTime, + CallBackProc callBack, + void *closure = NULL); + + CompWatchFdHandle + addWatchFd (int fd, + short int events, + CallBackProc callBack, + void *closure); + + void + removeWatchFd (CompWatchFdHandle handle); + + void * + removeTimeout (CompTimeoutHandle handle); + + // Wrapable interface + + WRAPABLE_HND(void, fileWatchAdded, CompFileWatch *) + WRAPABLE_HND(void, fileWatchRemoved, CompFileWatch *) + + WRAPABLE_HND(bool, initPluginForObject, CompPlugin *, CompObject *) + WRAPABLE_HND(void, finiPluginForObject, CompPlugin *, CompObject *) + + WRAPABLE_HND(bool, setOptionForPlugin, CompObject *, const char *, const char *, CompOptionValue *) + + WRAPABLE_HND(void, objectAdd, CompObject *, CompObject *) + WRAPABLE_HND(void, objectRemove, CompObject *, CompObject *) + + WRAPABLE_HND(void, sessionEvent, CompSessionEvent, CompOption *, unsigned int) + + private: + PrivateCore *priv; +}; + +#endif diff --git a/include/compdisplay.h b/include/compdisplay.h new file mode 100644 index 0000000..12e5aba --- /dev/null +++ b/include/compdisplay.h @@ -0,0 +1,427 @@ +#ifndef _COMPDISPLAY_H +#define _COMPDISPLAY_H + +#include <list> +#include "wrapable.h" + +class CompDisplay; +class CompScreen; +class PrivateDisplay; + + +class DisplayInterface : public WrapableInterface<CompDisplay> { + public: + DisplayInterface (); + + WRAPABLE_DEF(void, handleEvent, XEvent *event); + WRAPABLE_DEF(void, handleCompizEvent, const char *, + const char *, CompOption *, int nOption); + + WRAPABLE_DEF(bool, fileToImage, const char *, const char *, + int *, int *, int *, void **data); + WRAPABLE_DEF(bool, imageToFile, const char *, const char *, + const char *, int, int, int, void *); + + + WRAPABLE_DEF(void, matchInitExp, CompMatchExp *, const char *); + WRAPABLE_DEF(void, matchExpHandlerChanged) + WRAPABLE_DEF(void, matchPropertyChanged, CompWindow *) + + WRAPABLE_DEF(void, logMessage, const char *, CompLogLevel, const char*) +}; + +class CompDisplay : public WrapableHandler<DisplayInterface>, public CompObject { + + public: + CompDisplay *next; + char *screenPrivateIndices; + int screenPrivateLen; + + class Atoms { + public: + Atom supported; + Atom supportingWmCheck; + + Atom utf8String; + + Atom wmName; + + Atom winType; + Atom winTypeDesktop; + Atom winTypeDock; + Atom winTypeToolbar; + Atom winTypeMenu; + Atom winTypeUtil; + Atom winTypeSplash; + Atom winTypeDialog; + Atom winTypeNormal; + Atom winTypeDropdownMenu; + Atom winTypePopupMenu; + Atom winTypeTooltip; + Atom winTypeNotification; + Atom winTypeCombo; + Atom winTypeDnd; + + Atom winOpacity; + Atom winBrightness; + Atom winSaturation; + Atom winActive; + Atom winDesktop; + + Atom workarea; + + Atom desktopViewport; + Atom desktopGeometry; + Atom currentDesktop; + Atom numberOfDesktops; + + Atom winState; + Atom winStateModal; + Atom winStateSticky; + Atom winStateMaximizedVert; + Atom winStateMaximizedHorz; + Atom winStateShaded; + Atom winStateSkipTaskbar; + Atom winStateSkipPager; + Atom winStateHidden; + Atom winStateFullscreen; + Atom winStateAbove; + Atom winStateBelow; + Atom winStateDemandsAttention; + Atom winStateDisplayModal; + + Atom winActionMove; + Atom winActionResize; + Atom winActionStick; + Atom winActionMinimize; + Atom winActionMaximizeHorz; + Atom winActionMaximizeVert; + Atom winActionFullscreen; + Atom winActionClose; + Atom winActionShade; + Atom winActionChangeDesktop; + Atom winActionAbove; + Atom winActionBelow; + + Atom wmAllowedActions; + + Atom wmStrut; + Atom wmStrutPartial; + + Atom wmUserTime; + + Atom wmIcon; + Atom wmIconGeometry; + + Atom clientList; + Atom clientListStacking; + + Atom frameExtents; + Atom frameWindow; + + Atom wmState; + Atom wmChangeState; + Atom wmProtocols; + Atom wmClientLeader; + + Atom wmDeleteWindow; + Atom wmTakeFocus; + Atom wmPing; + Atom wmSyncRequest; + + Atom wmSyncRequestCounter; + + Atom closeWindow; + Atom wmMoveResize; + Atom moveResizeWindow; + Atom restackWindow; + + Atom showingDesktop; + + Atom xBackground[2]; + + Atom toolkitAction; + Atom toolkitActionMainMenu; + Atom toolkitActionRunDialog; + Atom toolkitActionWindowMenu; + Atom toolkitActionForceQuitDialog; + + Atom mwmHints; + + Atom xdndAware; + Atom xdndEnter; + Atom xdndLeave; + Atom xdndPosition; + Atom xdndStatus; + Atom xdndDrop; + + Atom manager; + Atom targets; + Atom multiple; + Atom timestamp; + Atom version; + Atom atomPair; + + Atom startupId; + }; + + public: + // functions + CompDisplay (); + ~CompDisplay (); + + bool + init (const char *name); + + bool + addScreen (int screenNum); + + void + removeScreen (CompScreen *); + + Atoms + atoms(); + + Display * + dpy(); + + CompScreen * + screens(); + + GLenum + textureFilter (); + + CompOption * + getOption (const char *); + + bool + setOption (const char *name, + CompOptionValue *value); + + XineramaScreenInfo * + screenInfo (); + + int + nScreenInfo (); + + bool + XRandr (); + + bool + XShape (); + + SnDisplay * + snDisplay (); + + Window + below (); + + Window + activeWindow (); + + Window + autoRaiseWindow (); + + XModifierKeymap * + modMap (); + + unsigned int + ignoredModMask (); + + const char * + displayString (); + + unsigned int + lastPing (); + + CompWatchFdHandle + getWatchFdHandle (); + + void + setWatchFdHandle (CompWatchFdHandle); + + void + processEvents (); + + void + updateModifierMappings (); + + unsigned int + virtualToRealModMask (unsigned int modMask); + + unsigned int + keycodeToModifiers (int keycode); + + CompScreen * + findScreen (Window root); + + void + forEachWindow (ForEachWindowProc proc, + void *closure); + + CompWindow * + findWindow (Window id); + + CompWindow * + findTopLevelWindow (Window id); + + + void + clearTargetOutput (unsigned int mask); + + bool + readImageFromFile (const char *name, + int *width, + int *height, + void **data); + + bool + writeImageToFile (const char *path, + const char *name, + const char *format, + int width, + int height, + void *data); + + CompCursor * + findCursor (); + + void + updateScreenInfo (); + + Window + getActiveWindow (Window root); + + int + getWmState (Window id); + + void + setWmState (int state, Window id); + + unsigned int + windowStateMask (Atom state); + + + static unsigned int + windowStateFromString (const char *str); + + unsigned int + getWindowState (Window id); + + void + setWindowState (unsigned int state, Window id); + + unsigned int + getWindowType (Window id); + + void + getMwmHints (Window id, + unsigned int *func, + unsigned int *decor); + + + unsigned int + getProtocols (Window id); + + + unsigned int + getWindowProp (Window id, + Atom property, + unsigned int defaultValue); + + + void + setWindowProp (Window id, + Atom property, + unsigned int value); + + + bool + readWindowProp32 (Window id, + Atom property, + unsigned short *returnValue); + + + unsigned short + getWindowProp32 (Window id, + Atom property, + unsigned short defaultValue); + + + void + setWindowProp32 (Window id, + Atom property, + unsigned short value); + + void + addScreenActions (CompScreen *s); + + // wrapable interface + WRAPABLE_HND(void, handleEvent, XEvent *event) + WRAPABLE_HND(void, handleCompizEvent, const char *, + const char *, CompOption *, int nOption) + + WRAPABLE_HND(bool, fileToImage, const char *, const char *, + int *, int *, int *, void **data) + WRAPABLE_HND(bool, imageToFile, const char *, const char *, + const char *, int, int, int, void *) + + + WRAPABLE_HND(void, matchInitExp, CompMatchExp *, const char *); + WRAPABLE_HND(void, matchExpHandlerChanged) + WRAPABLE_HND(void, matchPropertyChanged, CompWindow *) + + WRAPABLE_HND(void, logMessage, const char *, CompLogLevel, const char*) + + public: + Region mTmpRegion; + Region mOutputRegion; + + private: + + PrivateDisplay *priv; + + public: + + static bool + runCommandDispatch (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + runCommandScreenshot (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + runCommandWindowScreenshot (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + runCommandTerminal (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static CompOption * + getDisplayOptions (CompObject *object, + int *count); + + static bool + pingTimeout (void *closure); +}; + +extern Bool inHandleEvent; + +extern CompScreen *targetScreen; +extern CompOutput *targetOutput; + +#endif diff --git a/include/compiz-core.h b/include/compiz-core.h index 5d67aae..4b6ca55 100644 --- a/include/compiz-core.h +++ b/include/compiz-core.h @@ -26,7 +26,7 @@ #ifndef _COMPIZ_CORE_H #define _COMPIZ_CORE_H -#include <compiz-plugin.h> +#include <compplugin.h> #define CORE_ABIVERSION 20080618 @@ -48,6 +48,15 @@ #include <GL/gl.h> #include <GL/glx.h> + +#define TIMEVALDIFF(tv1, tv2) \ + ((tv1)->tv_sec == (tv2)->tv_sec || (tv1)->tv_usec >= (tv2)->tv_usec) ? \ + ((((tv1)->tv_sec - (tv2)->tv_sec) * 1000000) + \ + ((tv1)->tv_usec - (tv2)->tv_usec)) / 1000 : \ + ((((tv1)->tv_sec - 1 - (tv2)->tv_sec) * 1000000) + \ + (1000000 + (tv1)->tv_usec - (tv2)->tv_usec)) / 1000 + + COMPIZ_BEGIN_DECLS #if COMPOSITE_MAJOR > 0 || COMPOSITE_MINOR > 2 @@ -81,6 +90,8 @@ typedef struct _CompMatch CompMatch; typedef struct _CompOutput CompOutput; typedef struct _CompWalker CompWalker; +class CompDisplay; + /* virtual modifiers */ #define CompModAlt 0 @@ -228,7 +239,7 @@ extern int lastPointerY; extern int pointerX; extern int pointerY; -extern CompCore core; +extern CompCore *core; extern CompMetadata coreMetadata; #define RESTRICT_VALUE(value, min, max) \ @@ -276,11 +287,6 @@ typedef unsigned int CompObjectType; #define COMP_OBJECT_TYPE_SCREEN 2 #define COMP_OBJECT_TYPE_WINDOW 3 -struct _CompObject { - CompObjectType type; - CompPrivate *privates; - CompObject *parent; -}; typedef CompBool (*ObjectCallBackProc) (CompObject *object, void *closure); @@ -358,10 +364,7 @@ typedef enum { CompSessionPrevClientId } CompSessionClientIdType; -typedef void (*SessionEventProc) (CompCore *c, - CompSessionEvent event, - CompOption *arguments, - unsigned int nArguments); + void initSession (char *smPrevClientId); @@ -369,11 +372,6 @@ initSession (char *smPrevClientId); void closeSession (void); -void -sessionEvent (CompCore *c, - CompSessionEvent event, - CompOption *arguments, - unsigned int nArguments); char * getSessionClientId (CompSessionClientIdType type); @@ -427,7 +425,7 @@ typedef struct _CompButtonBinding { typedef struct _CompAction CompAction; -typedef Bool (*CompActionCallBackProc) (CompDisplay *d, +typedef bool (*CompActionCallBackProc) (CompDisplay *d, CompAction *action, CompActionState state, CompOption *option, @@ -598,143 +596,6 @@ isActionOption (CompOption *option); /* core.c */ -typedef CompBool (*InitPluginForObjectProc) (CompPlugin *plugin, - CompObject *object); -typedef void (*FiniPluginForObjectProc) (CompPlugin *plugin, - CompObject *object); - -typedef CompBool (*SetOptionForPluginProc) (CompObject *object, - const char *plugin, - const char *name, - CompOptionValue *value); - -typedef void (*ObjectAddProc) (CompObject *parent, - CompObject *object); -typedef void (*ObjectRemoveProc) (CompObject *parent, - CompObject *object); - -#define NOTIFY_CREATE_MASK (1 << 0) -#define NOTIFY_DELETE_MASK (1 << 1) -#define NOTIFY_MOVE_MASK (1 << 2) -#define NOTIFY_MODIFY_MASK (1 << 3) - -typedef void (*FileWatchCallBackProc) (const char *name, - void *closure); - -typedef int CompFileWatchHandle; - -typedef struct _CompFileWatch { - struct _CompFileWatch *next; - char *path; - int mask; - FileWatchCallBackProc callBack; - void *closure; - CompFileWatchHandle handle; -} CompFileWatch; - -typedef void (*FileWatchAddedProc) (CompCore *core, - CompFileWatch *fileWatch); - -typedef void (*FileWatchRemovedProc) (CompCore *core, - CompFileWatch *fileWatch); - -typedef struct _CompTimeout { - struct _CompTimeout *next; - int minTime; - int maxTime; - int minLeft; - int maxLeft; - CallBackProc callBack; - void *closure; - CompTimeoutHandle handle; -} CompTimeout; - -typedef struct _CompWatchFd { - struct _CompWatchFd *next; - int fd; - CallBackProc callBack; - void *closure; - CompWatchFdHandle handle; -} CompWatchFd; - -struct _CompCore { - CompObject base; - - CompDisplay *displays; - - Region tmpRegion; - Region outputRegion; - - CompFileWatch *fileWatch; - CompFileWatchHandle lastFileWatchHandle; - - CompTimeout *timeouts; - struct timeval lastTimeout; - CompTimeoutHandle lastTimeoutHandle; - - CompWatchFd *watchFds; - CompWatchFdHandle lastWatchFdHandle; - struct pollfd *watchPollFds; - int nWatchFds; - - InitPluginForObjectProc initPluginForObject; - FiniPluginForObjectProc finiPluginForObject; - - SetOptionForPluginProc setOptionForPlugin; - - ObjectAddProc objectAdd; - ObjectRemoveProc objectRemove; - - FileWatchAddedProc fileWatchAdded; - FileWatchRemovedProc fileWatchRemoved; - - SessionEventProc sessionEvent; -}; - -int -allocCoreObjectPrivateIndex (CompObject *parent); - -void -freeCoreObjectPrivateIndex (CompObject *parent, - int index); - -CompBool -forEachCoreObject (CompObject *parent, - ObjectCallBackProc proc, - void *closure); - -char * -nameCoreObject (CompObject *object); - -CompObject * -findCoreObject (CompObject *parent, - const char *name); - -CompBool -initCore (void); - -void -finiCore (void); - -int -allocateCorePrivateIndex (void); - -void -freeCorePrivateIndex (int index); - -void -addDisplayToCore (CompDisplay *d); - -CompFileWatchHandle -addFileWatch (const char *path, - int mask, - FileWatchCallBackProc callBack, - void *closure); - -void -removeFileWatch (CompFileWatchHandle handle); - - /* display.c */ #define COMP_DISPLAY_OPTION_ABI 0 @@ -782,60 +643,32 @@ removeFileWatch (CompFileWatchHandle handle); #define COMP_DISPLAY_OPTION_MAXIMIZE_WINDOW_KEY 42 #define COMP_DISPLAY_OPTION_MAXIMIZE_WINDOW_HORZ_KEY 43 #define COMP_DISPLAY_OPTION_MAXIMIZE_WINDOW_VERT_KEY 44 -#define COMP_DISPLAY_OPTION_OPACITY_INCREASE_BUTTON 45 -#define COMP_DISPLAY_OPTION_OPACITY_DECREASE_BUTTON 46 -#define COMP_DISPLAY_OPTION_SCREENSHOT 47 -#define COMP_DISPLAY_OPTION_RUN_SCREENSHOT_KEY 48 -#define COMP_DISPLAY_OPTION_WINDOW_SCREENSHOT 49 -#define COMP_DISPLAY_OPTION_RUN_WINDOW_SCREENSHOT_KEY 50 -#define COMP_DISPLAY_OPTION_WINDOW_MENU_BUTTON 51 -#define COMP_DISPLAY_OPTION_WINDOW_MENU_KEY 52 -#define COMP_DISPLAY_OPTION_SHOW_DESKTOP_KEY 53 -#define COMP_DISPLAY_OPTION_SHOW_DESKTOP_EDGE 54 -#define COMP_DISPLAY_OPTION_RAISE_ON_CLICK 55 -#define COMP_DISPLAY_OPTION_AUDIBLE_BELL 56 -#define COMP_DISPLAY_OPTION_TOGGLE_WINDOW_MAXIMIZED_KEY 57 -#define COMP_DISPLAY_OPTION_TOGGLE_WINDOW_MAXIMIZED_BUTTON 58 -#define COMP_DISPLAY_OPTION_TOGGLE_WINDOW_MAXIMIZED_HORZ_KEY 59 -#define COMP_DISPLAY_OPTION_TOGGLE_WINDOW_MAXIMIZED_VERT_KEY 60 -#define COMP_DISPLAY_OPTION_HIDE_SKIP_TASKBAR_WINDOWS 61 -#define COMP_DISPLAY_OPTION_TOGGLE_WINDOW_SHADED_KEY 62 -#define COMP_DISPLAY_OPTION_IGNORE_HINTS_WHEN_MAXIMIZED 63 -#define COMP_DISPLAY_OPTION_TERMINAL 64 -#define COMP_DISPLAY_OPTION_RUN_TERMINAL_KEY 65 -#define COMP_DISPLAY_OPTION_PING_DELAY 66 -#define COMP_DISPLAY_OPTION_EDGE_DELAY 67 -#define COMP_DISPLAY_OPTION_NUM 68 - -typedef void (*HandleEventProc) (CompDisplay *display, - XEvent *event); - -typedef void (*HandleCompizEventProc) (CompDisplay *display, - const char *pluginName, - const char *eventName, - CompOption *option, - int nOption); +#define COMP_DISPLAY_OPTION_SCREENSHOT 45 +#define COMP_DISPLAY_OPTION_RUN_SCREENSHOT_KEY 46 +#define COMP_DISPLAY_OPTION_WINDOW_SCREENSHOT 47 +#define COMP_DISPLAY_OPTION_RUN_WINDOW_SCREENSHOT_KEY 48 +#define COMP_DISPLAY_OPTION_WINDOW_MENU_BUTTON 49 +#define COMP_DISPLAY_OPTION_WINDOW_MENU_KEY 50 +#define COMP_DISPLAY_OPTION_SHOW_DESKTOP_KEY 51 +#define COMP_DISPLAY_OPTION_SHOW_DESKTOP_EDGE 52 +#define COMP_DISPLAY_OPTION_RAISE_ON_CLICK 53 +#define COMP_DISPLAY_OPTION_AUDIBLE_BELL 54 +#define COMP_DISPLAY_OPTION_TOGGLE_WINDOW_MAXIMIZED_KEY 55 +#define COMP_DISPLAY_OPTION_TOGGLE_WINDOW_MAXIMIZED_BUTTON 56 +#define COMP_DISPLAY_OPTION_TOGGLE_WINDOW_MAXIMIZED_HORZ_KEY 57 +#define COMP_DISPLAY_OPTION_TOGGLE_WINDOW_MAXIMIZED_VERT_KEY 58 +#define COMP_DISPLAY_OPTION_HIDE_SKIP_TASKBAR_WINDOWS 59 +#define COMP_DISPLAY_OPTION_TOGGLE_WINDOW_SHADED_KEY 60 +#define COMP_DISPLAY_OPTION_IGNORE_HINTS_WHEN_MAXIMIZED 61 +#define COMP_DISPLAY_OPTION_TERMINAL 62 +#define COMP_DISPLAY_OPTION_RUN_TERMINAL_KEY 63 +#define COMP_DISPLAY_OPTION_PING_DELAY 64 +#define COMP_DISPLAY_OPTION_EDGE_DELAY 65 +#define COMP_DISPLAY_OPTION_NUM 66 typedef void (*ForEachWindowProc) (CompWindow *window, void *closure); -typedef Bool (*FileToImageProc) (CompDisplay *display, - const char *path, - const char *name, - int *width, - int *height, - int *stride, - void **data); - -typedef Bool (*ImageToFileProc) (CompDisplay *display, - const char *path, - const char *name, - const char *format, - int width, - int height, - int stride, - void *data); - #define MATCH_OP_AND_MASK (1 << 0) #define MATCH_OP_NOT_MASK (1 << 1) @@ -883,221 +716,8 @@ union _CompMatchOp { CompMatchExpOp exp; }; -typedef void (*MatchInitExpProc) (CompDisplay *display, - CompMatchExp *exp, - const char *value); - -typedef void (*MatchExpHandlerChangedProc) (CompDisplay *display); - -typedef void (*MatchPropertyChangedProc) (CompDisplay *display, - CompWindow *window); - -typedef void (*LogMessageProc) (CompDisplay *d, - const char *componentName, - CompLogLevel level, - const char *message); - -struct _CompDisplay { - CompObject base; - - CompDisplay *next; - - xcb_connection_t *connection; - - Display *display; - CompScreen *screens; - - CompWatchFdHandle watchFdHandle; - - char *screenPrivateIndices; - int screenPrivateLen; - - int compositeEvent, compositeError, compositeOpcode; - int damageEvent, damageError; - int syncEvent, syncError; - int fixesEvent, fixesError, fixesVersion; - - Bool randrExtension; - int randrEvent, randrError; - - Bool shapeExtension; - int shapeEvent, shapeError; - - Bool xkbExtension; - int xkbEvent, xkbError; - - Bool xineramaExtension; - int xineramaEvent, xineramaError; - - XineramaScreenInfo *screenInfo; - int nScreenInfo; - - SnDisplay *snDisplay; - - Atom supportedAtom; - Atom supportingWmCheckAtom; - - Atom utf8StringAtom; - - Atom wmNameAtom; - - Atom winTypeAtom; - Atom winTypeDesktopAtom; - Atom winTypeDockAtom; - Atom winTypeToolbarAtom; - Atom winTypeMenuAtom; - Atom winTypeUtilAtom; - Atom winTypeSplashAtom; - Atom winTypeDialogAtom; - Atom winTypeNormalAtom; - Atom winTypeDropdownMenuAtom; - Atom winTypePopupMenuAtom; - Atom winTypeTooltipAtom; - Atom winTypeNotificationAtom; - Atom winTypeComboAtom; - Atom winTypeDndAtom; - - Atom winOpacityAtom; - Atom winBrightnessAtom; - Atom winSaturationAtom; - Atom winActiveAtom; - Atom winDesktopAtom; - - Atom workareaAtom; - - Atom desktopViewportAtom; - Atom desktopGeometryAtom; - Atom currentDesktopAtom; - Atom numberOfDesktopsAtom; - - Atom winStateAtom; - Atom winStateModalAtom; - Atom winStateStickyAtom; - Atom winStateMaximizedVertAtom; - Atom winStateMaximizedHorzAtom; - Atom winStateShadedAtom; - Atom winStateSkipTaskbarAtom; - Atom winStateSkipPagerAtom; - Atom winStateHiddenAtom; - Atom winStateFullscreenAtom; - Atom winStateAboveAtom; - Atom winStateBelowAtom; - Atom winStateDemandsAttentionAtom; - Atom winStateDisplayModalAtom; - - Atom winActionMoveAtom; - Atom winActionResizeAtom; - Atom winActionStickAtom; - Atom winActionMinimizeAtom; - Atom winActionMaximizeHorzAtom; - Atom winActionMaximizeVertAtom; - Atom winActionFullscreenAtom; - Atom winActionCloseAtom; - Atom winActionShadeAtom; - Atom winActionChangeDesktopAtom; - Atom winActionAboveAtom; - Atom winActionBelowAtom; - - Atom wmAllowedActionsAtom; - - Atom wmStrutAtom; - Atom wmStrutPartialAtom; - - Atom wmUserTimeAtom; - - Atom wmIconAtom; - Atom wmIconGeometryAtom; - - Atom clientListAtom; - Atom clientListStackingAtom; - - Atom frameExtentsAtom; - Atom frameWindowAtom; - - Atom wmStateAtom; - Atom wmChangeStateAtom; - Atom wmProtocolsAtom; - Atom wmClientLeaderAtom; - - Atom wmDeleteWindowAtom; - Atom wmTakeFocusAtom; - Atom wmPingAtom; - Atom wmSyncRequestAtom; - - Atom wmSyncRequestCounterAtom; - Atom closeWindowAtom; - Atom wmMoveResizeAtom; - Atom moveResizeWindowAtom; - Atom restackWindowAtom; - Atom showingDesktopAtom; - - Atom xBackgroundAtom[2]; - - Atom toolkitActionAtom; - Atom toolkitActionMainMenuAtom; - Atom toolkitActionRunDialogAtom; - Atom toolkitActionWindowMenuAtom; - Atom toolkitActionForceQuitDialogAtom; - - Atom mwmHintsAtom; - - Atom xdndAwareAtom; - Atom xdndEnterAtom; - Atom xdndLeaveAtom; - Atom xdndPositionAtom; - Atom xdndStatusAtom; - Atom xdndDropAtom; - - Atom managerAtom; - Atom targetsAtom; - Atom multipleAtom; - Atom timestampAtom; - Atom versionAtom; - Atom atomPairAtom; - - Atom startupIdAtom; - - unsigned int lastPing; - CompTimeoutHandle pingHandle; - - GLenum textureFilter; - - Window activeWindow; - - Window below; - char displayString[256]; - - XModifierKeymap *modMap; - unsigned int modMask[CompModNum]; - unsigned int ignoredModMask; - - KeyCode escapeKeyCode; - KeyCode returnKeyCode; - - CompOption opt[COMP_DISPLAY_OPTION_NUM]; - - CompTimeoutHandle autoRaiseHandle; - Window autoRaiseWindow; - - CompTimeoutHandle edgeDelayHandle; - - CompOptionValue plugin; - Bool dirtyPluginList; - - HandleEventProc handleEvent; - HandleCompizEventProc handleCompizEvent; - - FileToImageProc fileToImage; - ImageToFileProc imageToFile; - - MatchInitExpProc matchInitExp; - MatchExpHandlerChangedProc matchExpHandlerChanged; - MatchPropertyChangedProc matchPropertyChanged; - - LogMessageProc logMessage; -}; #define GET_CORE_DISPLAY(object) ((CompDisplay *) (object)) #define CORE_DISPLAY(object) CompDisplay *d = GET_CORE_DISPLAY (object) @@ -1131,14 +751,8 @@ allocateDisplayPrivateIndex (void); void freeDisplayPrivateIndex (int index); -CompOption * -getDisplayOptions (CompPlugin *plugin, - CompDisplay *display, - int *count); - -Bool -setDisplayOption (CompPlugin *plugin, - CompDisplay *display, +bool +setDisplayOption (CompObject *object, const char *name, CompOptionValue *value); @@ -1149,12 +763,6 @@ compLogMessage (CompDisplay *d, const char *format, ...); -void -logMessage (CompDisplay *d, - const char *componentName, - CompLogLevel level, - const char *message); - const char * logLevelToString (CompLogLevel level); @@ -1162,58 +770,6 @@ int compCheckForError (Display *dpy); void -addScreenToDisplay (CompDisplay *display, - CompScreen *s); - -Bool -addDisplay (const char *name); - -void -removeDisplay (CompDisplay *d); - -Time -getCurrentTimeFromDisplay (CompDisplay *d); - -void -forEachWindowOnDisplay (CompDisplay *display, - ForEachWindowProc proc, - void *closure); - -CompScreen * -findScreenAtDisplay (CompDisplay *d, - Window root); - -CompWindow * -findWindowAtDisplay (CompDisplay *display, - Window id); - -CompWindow * -findTopLevelWindowAtDisplay (CompDisplay *d, - Window id); - -unsigned int -virtualToRealModMask (CompDisplay *d, - unsigned int modMask); - -void -updateModifierMappings (CompDisplay *d); - -unsigned int -keycodeToModifiers (CompDisplay *d, - int keycode); - -void -eventLoop (void); - -void -handleSelectionRequest (CompDisplay *display, - XEvent *event); - -void -handleSelectionClear (CompDisplay *display, - XEvent *event); - -void warpPointer (CompScreen *screen, int dx, int dy); @@ -1223,44 +779,6 @@ setDisplayAction (CompDisplay *display, CompOption *o, CompOptionValue *value); -Bool -readImageFromFile (CompDisplay *display, - const char *name, - int *width, - int *height, - void **data); - -Bool -writeImageToFile (CompDisplay *display, - const char *path, - const char *name, - const char *format, - int width, - int height, - void *data); - -Bool -fileToImage (CompDisplay *display, - const char *path, - const char *name, - int *width, - int *height, - int *stride, - void **data); - -Bool -imageToFile (CompDisplay *display, - const char *path, - const char *name, - const char *format, - int width, - int height, - int stride, - void *data); - -CompCursor * -findCursorAtDisplay (CompDisplay *display); - /* event.c */ @@ -1275,16 +793,6 @@ typedef struct _CompDelayedEdgeSettings unsigned int nOption; } CompDelayedEdgeSettings; -void -handleEvent (CompDisplay *display, - XEvent *event); - -void -handleCompizEvent (CompDisplay *display, - const char *pluginName, - const char *eventName, - CompOption *option, - int nOption); void handleSyncAlarm (CompWindow *w); @@ -1299,10 +807,6 @@ eventTerminates (CompDisplay *display, XEvent *event, CompOption *option); -void -clearTargetOutput (CompDisplay *display, - unsigned int mask); - /* paint.c */ #define MULTIPLY_USHORT(us1, us2) \ @@ -1366,12 +870,6 @@ typedef struct _CompMatrix { #define COMP_TEX_COORD_YX(m, vx, vy) \ ((m)->yx * (vx) + (m)->yy * (vy) + (m)->y0) - -typedef void (*PreparePaintScreenProc) (CompScreen *screen, - int msSinceLastPaint); - -typedef void (*DonePaintScreenProc) (CompScreen *screen); - #define PAINT_SCREEN_REGION_MASK (1 << 0) #define PAINT_SCREEN_FULL_MASK (1 << 1) #define PAINT_SCREEN_TRANSFORMED_MASK (1 << 2) @@ -1380,37 +878,7 @@ typedef void (*DonePaintScreenProc) (CompScreen *screen); #define PAINT_SCREEN_NO_OCCLUSION_DETECTION_MASK (1 << 5) #define PAINT_SCREEN_NO_BACKGROUND_MASK (1 << 6) -typedef void (*PaintScreenProc) (CompScreen *screen, - CompOutput *outputs, - int numOutput, - unsigned int mask); - -typedef Bool (*PaintOutputProc) (CompScreen *screen, - const ScreenPaintAttrib *sAttrib, - const CompTransform *transform, - Region region, - CompOutput *output, - unsigned int mask); - -typedef void (*PaintTransformedOutputProc) (CompScreen *screen, - const ScreenPaintAttrib *sAttrib, - const CompTransform *transform, - Region region, - CompOutput *output, - unsigned int mask); - -/* XXX: ApplyScreenTransformProc will be removed */ -typedef void (*ApplyScreenTransformProc) (CompScreen *screen, - const ScreenPaintAttrib *sAttrib, - CompOutput *output, - CompTransform *transform); - -typedef void (*EnableOutputClippingProc) (CompScreen *screen, - const CompTransform *transform, - Region region, - CompOutput *output); - -typedef void (*DisableOutputClippingProc) (CompScreen *screen); + typedef void (*WalkerFiniProc) (CompScreen *screen, CompWalker *walker); @@ -1479,48 +947,6 @@ struct _CompWalker { #define PAINT_WINDOW_BLEND_MASK (1 << 19) -typedef Bool (*PaintWindowProc) (CompWindow *window, - const WindowPaintAttrib *attrib, - const CompTransform *transform, - Region region, - unsigned int mask); - -typedef Bool (*DrawWindowProc) (CompWindow *window, - const CompTransform *transform, - const FragmentAttrib *fragment, - Region region, - unsigned int mask); - -typedef void (*AddWindowGeometryProc) (CompWindow *window, - CompMatrix *matrix, - int nMatrix, - Region region, - Region clip); - -typedef void (*DrawWindowTextureProc) (CompWindow *w, - CompTexture *texture, - const FragmentAttrib *fragment, - unsigned int mask); - -typedef void (*DrawWindowGeometryProc) (CompWindow *window); - -typedef void (*PaintCursorProc) (CompCursor *cursor, - const CompTransform *transform, - Region region, - unsigned int mask); - -void -preparePaintScreen (CompScreen *screen, - int msSinceLastPaint); - -void -donePaintScreen (CompScreen *screen); - -void -transformToScreenSpace (CompScreen *screen, - CompOutput *output, - float z, - CompTransform *transform); /* XXX: prepareXCoords will be removed */ void @@ -1528,43 +954,6 @@ prepareXCoords (CompScreen *screen, CompOutput *output, float z); -void -paintTransformedOutput (CompScreen *screen, - const ScreenPaintAttrib *sAttrib, - const CompTransform *transform, - Region region, - CompOutput *output, - unsigned int mask); - -/* XXX: applyScreenTransform will be removed */ -void -applyScreenTransform (CompScreen *screen, - const ScreenPaintAttrib *sAttrib, - CompOutput *output, - CompTransform *transform); - -void -enableOutputClipping (CompScreen *screen, - const CompTransform *transform, - Region region, - CompOutput *output); - -void -disableOutputClipping (CompScreen *screen); - -void -paintScreen (CompScreen *screen, - CompOutput *outputs, - int numOutput, - unsigned int mask); - -Bool -paintOutput (CompScreen *screen, - const ScreenPaintAttrib *sAttrib, - const CompTransform *transform, - Region region, - CompOutput *output, - unsigned int mask); Bool moreWindowVertices (CompWindow *w, @@ -1581,32 +970,6 @@ addWindowGeometry (CompWindow *w, Region region, Region clip); -void -drawWindowTexture (CompWindow *w, - CompTexture *texture, - const FragmentAttrib *fragment, - unsigned int mask); - -Bool -drawWindow (CompWindow *w, - const CompTransform *transform, - const FragmentAttrib *fragment, - Region region, - unsigned int mask); - -Bool -paintWindow (CompWindow *w, - const WindowPaintAttrib *attrib, - const CompTransform *transform, - Region region, - unsigned int mask); - -void -paintCursor (CompCursor *cursor, - const CompTransform *transform, - Region region, - unsigned int mask); - /* texture.c */ #define POWER_OF_TWO(v) ((v & (v - 1)) == 0) @@ -1674,22 +1037,8 @@ Bool iconToTexture (CompScreen *screen, CompIcon *icon); -Bool -bindPixmapToTexture (CompScreen *screen, - CompTexture *texture, - Pixmap pixmap, - int width, - int height, - int depth); -void -releasePixmapFromTexture (CompScreen *screen, - CompTexture *texture); -void -enableTexture (CompScreen *screen, - CompTexture *texture, - CompTextureFilter filter); void enableTextureClampToBorder (CompScreen *screen, @@ -1701,10 +1050,6 @@ enableTextureClampToEdge (CompScreen *screen, CompTexture *texture, CompTextureFilter filter); -void -disableTexture (CompScreen *screen, - CompTexture *texture); - /* screen.c */ @@ -1723,11 +1068,9 @@ disableTexture (CompScreen *screen, #define COMP_SCREEN_OPTION_OVERLAPPING_OUTPUTS 12 #define COMP_SCREEN_OPTION_FOCUS_PREVENTION_LEVEL 13 #define COMP_SCREEN_OPTION_FOCUS_PREVENTION_MATCH 14 -#define COMP_SCREEN_OPTION_OPACITY_MATCHES 15 -#define COMP_SCREEN_OPTION_OPACITY_VALUES 16 -#define COMP_SCREEN_OPTION_TEXTURE_COMPRESSION 17 -#define COMP_SCREEN_OPTION_FORCE_INDEPENDENT 18 -#define COMP_SCREEN_OPTION_NUM 19 +#define COMP_SCREEN_OPTION_TEXTURE_COMPRESSION 15 +#define COMP_SCREEN_OPTION_FORCE_INDEPENDENT 16 +#define COMP_SCREEN_OPTION_NUM 17 #ifndef GLX_EXT_texture_from_pixmap #define GLX_BIND_TO_TEXTURE_RGB_EXT 0x20D0 @@ -1844,10 +1187,7 @@ typedef void (*GLGenerateMipmapProc) (GLenum target); #define MAX_DEPTH 32 -typedef void (*EnterShowDesktopModeProc) (CompScreen *screen); -typedef void (*LeaveShowDesktopModeProc) (CompScreen *screen, - CompWindow *window); typedef Bool (*DamageWindowRectProc) (CompWindow *w, Bool initial, @@ -1856,10 +1196,6 @@ typedef Bool (*DamageWindowRectProc) (CompWindow *w, typedef Bool (*DamageWindowRegionProc) (CompWindow *w, Region region); -typedef Bool (*DamageCursorRectProc) (CompCursor *c, - Bool initial, - BoxPtr rect); - typedef void (*GetOutputExtentsForWindowProc) (CompWindow *w, CompWindowExtents *output); @@ -1898,21 +1234,9 @@ typedef void (*WindowMoveNotifyProc) (CompWindow *window, #define CompWindowGrabMoveMask (1 << 2) #define CompWindowGrabResizeMask (1 << 3) -typedef void (*WindowGrabNotifyProc) (CompWindow *window, - int x, - int y, - unsigned int state, - unsigned int mask); -typedef void (*WindowUngrabNotifyProc) (CompWindow *window); -typedef void (*WindowStateChangeNotifyProc) (CompWindow *window, - unsigned int lastState); -typedef void (*OutputChangeNotifyProc) (CompScreen *screen); - -typedef void (*InitWindowWalkerProc) (CompScreen *screen, - CompWalker *walker); #define COMP_SCREEN_DAMAGE_PENDING_MASK (1 << 0) #define COMP_SCREEN_DAMAGE_REGION_MASK (1 << 1) @@ -2025,214 +1349,6 @@ typedef struct _CompActiveWindowHistory { int activeNum; } CompActiveWindowHistory; -struct _CompScreen { - CompObject base; - - CompScreen *next; - CompDisplay *display; - CompWindow *windows; - CompWindow *reverseWindows; - - char *windowPrivateIndices; - int windowPrivateLen; - - Colormap colormap; - int screenNum; - int width; - int height; - int x; - int y; - int hsize; /* Number of horizontal viewports */ - int vsize; /* Number of vertical viewports */ - unsigned int nDesktop; - unsigned int currentDesktop; - REGION region; - Region damage; - unsigned long damageMask; - Window root; - Window overlay; - Window output; - XWindowAttributes attrib; - Window grabWindow; - CompFBConfig glxPixmapFBConfigs[MAX_DEPTH + 1]; - int textureRectangle; - int textureNonPowerOfTwo; - int textureEnvCombine; - int textureEnvCrossbar; - int textureBorderClamp; - int textureCompression; - GLint maxTextureSize; - int fbo; - int fragmentProgram; - int maxTextureUnits; - Cursor invisibleCursor; - XRectangle *exposeRects; - int sizeExpose; - int nExpose; - CompTexture backgroundTexture; - Bool backgroundLoaded; - unsigned int pendingDestroys; - int desktopWindowCount; - unsigned int mapNum; - unsigned int activeNum; - - CompOutput *outputDev; - int nOutputDev; - int currentOutputDev; - CompOutput fullscreenOutput; - Bool hasOverlappingOutputs; - - int windowOffsetX; - int windowOffsetY; - - XRectangle lastViewport; - - CompActiveWindowHistory history[ACTIVE_WINDOW_HISTORY_NUM]; - int currentHistory; - - int overlayWindowCount; - - CompScreenEdge screenEdge[SCREEN_EDGE_NUM]; - - SnMonitorContext *snContext; - CompStartupSequence *startupSequences; - unsigned int startupSequenceTimeoutHandle; - - int filter[3]; - - CompGroup *groups; - - CompIcon *defaultIcon; - - Bool canDoSaturated; - Bool canDoSlightlySaturated; - - Window wmSnSelectionWindow; - Atom wmSnAtom; - Time wmSnTimestamp; - - Cursor normalCursor; - Cursor busyCursor; - - CompWindow **clientList; - int nClientList; - - CompButtonGrab *buttonGrab; - int nButtonGrab; - CompKeyGrab *keyGrab; - int nKeyGrab; - - CompGrab *grabs; - int grabSize; - int maxGrab; - - int rasterX; - int rasterY; - struct timeval lastRedraw; - int nextRedraw; - int redrawTime; - int optimalRedrawTime; - int frameStatus; - int timeMult; - Bool idle; - int timeLeft; - Bool pendingCommands; - - int lastFunctionId; - - CompFunction *fragmentFunctions; - CompProgram *fragmentPrograms; - - int saturateFunction[2][64]; - - GLfloat projection[16]; - - Bool clearBuffers; - - Bool lighting; - Bool slowAnimations; - - XRectangle workArea; - - unsigned int showingDesktopMask; - - unsigned long *desktopHintData; - int desktopHintSize; - - CompCursor *cursors; - CompCursorImage *cursorImages; - - GLXGetProcAddressProc getProcAddress; - GLXBindTexImageProc bindTexImage; - GLXReleaseTexImageProc releaseTexImage; - GLXQueryDrawableProc queryDrawable; - GLXCopySubBufferProc copySubBuffer; - GLXGetVideoSyncProc getVideoSync; - GLXWaitVideoSyncProc waitVideoSync; - GLXGetFBConfigsProc getFBConfigs; - GLXGetFBConfigAttribProc getFBConfigAttrib; - GLXCreatePixmapProc createPixmap; - - GLActiveTextureProc activeTexture; - GLClientActiveTextureProc clientActiveTexture; - GLMultiTexCoord2fProc multiTexCoord2f; - - GLGenProgramsProc genPrograms; - GLDeleteProgramsProc deletePrograms; - GLBindProgramProc bindProgram; - GLProgramStringProc programString; - GLProgramParameter4fProc programEnvParameter4f; - GLProgramParameter4fProc programLocalParameter4f; - GLGetProgramivProc getProgramiv; - - GLGenFramebuffersProc genFramebuffers; - GLDeleteFramebuffersProc deleteFramebuffers; - GLBindFramebufferProc bindFramebuffer; - GLCheckFramebufferStatusProc checkFramebufferStatus; - GLFramebufferTexture2DProc framebufferTexture2D; - GLGenerateMipmapProc generateMipmap; - - GLXContext ctx; - - CompOption opt[COMP_SCREEN_OPTION_NUM]; - - PreparePaintScreenProc preparePaintScreen; - DonePaintScreenProc donePaintScreen; - PaintScreenProc paintScreen; - PaintOutputProc paintOutput; - PaintTransformedOutputProc paintTransformedOutput; - EnableOutputClippingProc enableOutputClipping; - DisableOutputClippingProc disableOutputClipping; - ApplyScreenTransformProc applyScreenTransform; - PaintWindowProc paintWindow; - DrawWindowProc drawWindow; - AddWindowGeometryProc addWindowGeometry; - DrawWindowTextureProc drawWindowTexture; - DamageWindowRectProc damageWindowRect; - GetOutputExtentsForWindowProc getOutputExtentsForWindow; - GetAllowedActionsForWindowProc getAllowedActionsForWindow; - FocusWindowProc focusWindow; - ActivateWindowProc activateWindow; - PlaceWindowProc placeWindow; - ValidateWindowResizeRequestProc validateWindowResizeRequest; - - PaintCursorProc paintCursor; - DamageCursorRectProc damageCursorRect; - - WindowResizeNotifyProc windowResizeNotify; - WindowMoveNotifyProc windowMoveNotify; - WindowGrabNotifyProc windowGrabNotify; - WindowUngrabNotifyProc windowUngrabNotify; - - EnterShowDesktopModeProc enterShowDesktopMode; - LeaveShowDesktopModeProc leaveShowDesktopMode; - - WindowStateChangeNotifyProc windowStateChangeNotify; - - OutputChangeNotifyProc outputChangeNotify; - - InitWindowWalkerProc initWindowWalker; -}; #define GET_CORE_SCREEN(object) ((CompScreen *) (object)) #define CORE_SCREEN(object) CompScreen *s = GET_CORE_SCREEN (object) @@ -2267,282 +1383,15 @@ void freeScreenPrivateIndex (CompDisplay *display, int index); -CompOption * -getScreenOptions (CompPlugin *plugin, - CompScreen *screen, - int *count); - -Bool -setScreenOption (CompPlugin *plugin, - CompScreen *screen, +bool +setScreenOption (CompObject *object, const char *name, CompOptionValue *value); -void -configureScreen (CompScreen *s, - XConfigureEvent *ce); - -void -setCurrentOutput (CompScreen *s, - int outputNum); - -void -updateScreenBackground (CompScreen *screen, - CompTexture *texture); - -void -detectRefreshRateOfScreen (CompScreen *s); - -void -showOutputWindow (CompScreen *s); - -void -hideOutputWindow (CompScreen *s); - -void -updateOutputWindow (CompScreen *s); - -Bool -addScreen (CompDisplay *display, - int screenNum, - Window wmSnSelectionWindow, - Atom wmSnAtom, - Time wmSnTimestamp); - -void -removeScreen (CompScreen *s); - -void -damageScreenRegion (CompScreen *screen, - Region region); - -void -damageScreen (CompScreen *screen); - -void -damagePendingOnScreen (CompScreen *s); - -void -insertWindowIntoScreen (CompScreen *s, - CompWindow *w, - Window aboveId); - -void -unhookWindowFromScreen (CompScreen *s, - CompWindow *w); - -void -forEachWindowOnScreen (CompScreen *screen, - ForEachWindowProc proc, - void *closure); - -CompWindow * -findWindowAtScreen (CompScreen *s, - Window id); - -CompWindow * -findTopLevelWindowAtScreen (CompScreen *s, - Window id); - -void -focusDefaultWindow (CompScreen *s); - -int -pushScreenGrab (CompScreen *s, - Cursor cursor, - const char *name); - -void -updateScreenGrab (CompScreen *s, - int index, - Cursor cursor); - -void -removeScreenGrab (CompScreen *s, - int index, - XPoint *restorePointer); - -Bool -otherScreenGrabExist (CompScreen *s, ...); - -Bool -addScreenAction (CompScreen *s, - CompAction *action); - -void -removeScreenAction (CompScreen *s, - CompAction *action); - -void -updatePassiveGrabs (CompScreen *s); - -void -updateWorkareaForScreen (CompScreen *s); - -void -updateClientListForScreen (CompScreen *s); - -Window -getActiveWindow (CompDisplay *display, - Window root); - -void -toolkitAction (CompScreen *s, - Atom toolkitAction, - Time eventTime, - Window window, - long data0, - long data1, - long data2); - -void -runCommand (CompScreen *s, - const char *command); - -void -moveScreenViewport (CompScreen *s, - int tx, - int ty, - Bool sync); - -void -moveWindowToViewportPosition (CompWindow *w, - int x, - int y, - Bool sync); - -CompGroup * -addGroupToScreen (CompScreen *s, - Window id); -void -removeGroupFromScreen (CompScreen *s, - CompGroup *group); - -CompGroup * -findGroupAtScreen (CompScreen *s, - Window id); - -void -applyStartupProperties (CompScreen *screen, - CompWindow *window); - -void -sendWindowActivationRequest (CompScreen *s, - Window id); - -void -screenTexEnvMode (CompScreen *s, - GLenum mode); - -void -screenLighting (CompScreen *s, - Bool lighting); - -void -enableScreenEdge (CompScreen *s, - int edge); - -void -disableScreenEdge (CompScreen *s, - int edge); - -Window -getTopWindow (CompScreen *s); - -void -makeScreenCurrent (CompScreen *s); - -void -finishScreenDrawing (CompScreen *s); - -int -outputDeviceForPoint (CompScreen *s, - int x, - int y); - -void -getCurrentOutputExtents (CompScreen *s, - int *x1, - int *y1, - int *x2, - int *y2); - -void -getWorkareaForOutput (CompScreen *s, - int output, - XRectangle *area); - -void -setNumberOfDesktops (CompScreen *s, - unsigned int nDesktop); - -void -setCurrentDesktop (CompScreen *s, - unsigned int desktop); - -void -setDefaultViewport (CompScreen *s); - -void -outputChangeNotify (CompScreen *s); - -void -clearScreenOutput (CompScreen *s, - CompOutput *output, - unsigned int mask); - -void -viewportForGeometry (CompScreen *s, - int x, - int y, - int width, - int height, - int borderWidth, - int *viewportX, - int *viewportY); - -int -outputDeviceForGeometry (CompScreen *s, - int x, - int y, - int width, - int height, - int borderWidth); - -Bool -updateDefaultIcon (CompScreen *screen); - -CompCursor * -findCursorAtScreen (CompScreen *screen); - -CompCursorImage * -findCursorImageAtScreen (CompScreen *screen, - unsigned long serial); - -void -setCurrentActiveWindowHistory (CompScreen *s, - int x, - int y); - -void -addToCurrentActiveWindowHistory (CompScreen *s, - Window id); - -void -setWindowPaintOffset (CompScreen *s, - int x, - int y); /* window.c */ -#define WINDOW_INVISIBLE(w) \ - ((w)->attrib.map_state != IsViewable || \ - (!(w)->damaged) || \ - (w)->attrib.x + (w)->width + (w)->output.right <= 0 || \ - (w)->attrib.y + (w)->height + (w)->output.bottom <= 0 || \ - (w)->attrib.x - (w)->output.left >= (w)->screen->width || \ - (w)->attrib.y - (w)->output.top >= (w)->screen->height) typedef enum { CompStackingUpdateModeNone = 0, @@ -2566,140 +1415,6 @@ typedef struct _CompStruts { XRectangle bottom; } CompStruts; -struct _CompWindow { - CompObject base; - - CompScreen *screen; - CompWindow *next; - CompWindow *prev; - - int refcnt; - Window id; - Window frame; - unsigned int mapNum; - unsigned int activeNum; - XWindowAttributes attrib; - int serverX; - int serverY; - int serverWidth; - int serverHeight; - int serverBorderWidth; - Window transientFor; - Window clientLeader; - XSizeHints sizeHints; - Pixmap pixmap; - CompTexture *texture; - CompMatrix matrix; - Damage damage; - Bool inputHint; - Bool alpha; - GLint width; - GLint height; - Region region; - Region clip; - unsigned int wmType; - unsigned int type; - unsigned int state; - unsigned int actions; - unsigned int protocols; - unsigned int mwmDecor; - unsigned int mwmFunc; - Bool invisible; - Bool destroyed; - Bool damaged; - Bool redirected; - Bool managed; - Bool bindFailed; - Bool overlayWindow; - int destroyRefCnt; - int unmapRefCnt; - - unsigned int initialViewportX; - unsigned int initialViewportY; - - Time initialTimestamp; - Bool initialTimestampSet; - - Bool placed; - Bool minimized; - Bool inShowDesktopMode; - Bool shaded; - Bool hidden; - Bool grabbed; - - unsigned int desktop; - - int pendingUnmaps; - int pendingMaps; - - char *startupId; - char *resName; - char *resClass; - - CompGroup *group; - - unsigned int lastPong; - Bool alive; - - GLushort opacity; - GLushort brightness; - GLushort saturation; - - Bool opacityPropSet; - int opacityFactor; - - WindowPaintAttrib paint; - WindowPaintAttrib lastPaint; - - unsigned int lastMask; - - CompWindowExtents input; - CompWindowExtents output; - - CompStruts *struts; - - CompIcon **icon; - int nIcon; - - XRectangle iconGeometry; - Bool iconGeometrySet; - - XWindowChanges saveWc; - int saveMask; - - XSyncCounter syncCounter; - XSyncValue syncValue; - XSyncAlarm syncAlarm; - unsigned long syncAlarmConnection; - unsigned int syncWaitHandle; - - Bool syncWait; - int syncX; - int syncY; - int syncWidth; - int syncHeight; - int syncBorderWidth; - - Bool closeRequests; - Time lastCloseRequestTime; - - XRectangle *damageRects; - int sizeDamage; - int nDamage; - - GLfloat *vertices; - int vertexSize; - int vertexStride; - GLushort *indices; - int indexSize; - int vCount; - int texUnits; - int texCoordSize; - int indexCount; - - /* must be set by addWindowGeometry */ - DrawWindowGeometryProc drawWindowGeometry; -}; #define GET_CORE_WINDOW(object) ((CompWindow *) (object)) #define CORE_WINDOW(object) CompWindow *w = GET_CORE_WINDOW (object) @@ -2734,385 +1449,6 @@ void freeWindowPrivateIndex (CompScreen *screen, int index); -unsigned int -windowStateMask (CompDisplay *display, - Atom state); - -unsigned int -windowStateFromString (const char *str); - -unsigned int -getWindowState (CompDisplay *display, - Window id); - -void -setWindowState (CompDisplay *display, - unsigned int state, - Window id); - -void -changeWindowState (CompWindow *w, - unsigned int newState); - -void -recalcWindowActions (CompWindow *w); - -unsigned int -constrainWindowState (unsigned int state, - unsigned int actions); - -unsigned int -windowTypeFromString (const char *str); - -unsigned int -getWindowType (CompDisplay *display, - Window id); - -void -recalcWindowType (CompWindow *w); - -void -getMwmHints (CompDisplay *display, - Window id, - unsigned int *func, - unsigned int *decor); - -unsigned int -getProtocols (CompDisplay *display, - Window id); - -unsigned int -getWindowProp (CompDisplay *display, - Window id, - Atom property, - unsigned int defaultValue); - -void -setWindowProp (CompDisplay *display, - Window id, - Atom property, - unsigned int value); - -Bool -readWindowProp32 (CompDisplay *display, - Window id, - Atom property, - unsigned short *returnValue); - -unsigned short -getWindowProp32 (CompDisplay *display, - Window id, - Atom property, - unsigned short defaultValue); - -void -setWindowProp32 (CompDisplay *display, - Window id, - Atom property, - unsigned short value); - -void -updateWindowOpacity (CompWindow *window); - -void -updateNormalHints (CompWindow *window); - -void -updateWmHints (CompWindow *w); - -void -updateWindowClassHints (CompWindow *window); - -void -updateTransientHint (CompWindow *w); - -void -updateIconGeometry (CompWindow *w); - -Window -getClientLeader (CompWindow *w); - -char * -getStartupId (CompWindow *w); - -int -getWmState (CompDisplay *display, - Window id); - -void -setWmState (CompDisplay *display, - int state, - Window id); - -void -setWindowFrameExtents (CompWindow *w, - CompWindowExtents *input); - -void -updateWindowOutputExtents (CompWindow *w); - -void -updateWindowRegion (CompWindow *w); - -Bool -updateWindowStruts (CompWindow *w); - -void -addWindow (CompScreen *screen, - Window id, - Window aboveId); - -void -removeWindow (CompWindow *w); - -void -destroyWindow (CompWindow *w); - -void -sendConfigureNotify (CompWindow *w); - -void -mapWindow (CompWindow *w); - -void -unmapWindow (CompWindow *w); - -Bool -bindWindow (CompWindow *w); - -void -releaseWindow (CompWindow *w); - -void -moveWindow (CompWindow *w, - int dx, - int dy, - Bool damage, - Bool immediate); - -void -configureXWindow (CompWindow *w, - unsigned int valueMask, - XWindowChanges *xwc); - -unsigned int -adjustConfigureRequestForGravity (CompWindow *w, - XWindowChanges *xwc, - unsigned int xwcm, - int gravity); - -void -moveResizeWindow (CompWindow *w, - XWindowChanges *xwc, - unsigned int xwcm, - int gravity); - -void -syncWindowPosition (CompWindow *w); - -void -sendSyncRequest (CompWindow *w); - -Bool -resizeWindow (CompWindow *w, - int x, - int y, - int width, - int height, - int borderWidth); - -void -configureWindow (CompWindow *w, - XConfigureEvent *ce); - -void -circulateWindow (CompWindow *w, - XCirculateEvent *ce); - -void -addWindowDamageRect (CompWindow *w, - BoxPtr rect); - -void -getOutputExtentsForWindow (CompWindow *w, - CompWindowExtents *output); - -void -getAllowedActionsForWindow (CompWindow *w, - unsigned int *setActions, - unsigned int *clearActions); - -void -addWindowDamage (CompWindow *w); - -void -damageWindowOutputExtents (CompWindow *w); - -Bool -damageWindowRect (CompWindow *w, - Bool initial, - BoxPtr rect); - -void -damageTransformedWindowRect (CompWindow *w, - float xScale, - float yScale, - float xTranslate, - float yTranslate, - BoxPtr rect); - -Bool -focusWindow (CompWindow *w); - -Bool -placeWindow (CompWindow *w, - int x, - int y, - int *newX, - int *newY); - -void -validateWindowResizeRequest (CompWindow *w, - unsigned int *mask, - XWindowChanges *xwc); - -void -windowResizeNotify (CompWindow *w, - int dx, - int dy, - int dwidth, - int dheight); - -void -windowMoveNotify (CompWindow *w, - int dx, - int dy, - Bool immediate); - -void -windowGrabNotify (CompWindow *w, - int x, - int y, - unsigned int state, - unsigned int mask); - -void -windowUngrabNotify (CompWindow *w); - -void -windowStateChangeNotify (CompWindow *w, - unsigned int lastState); - -void -moveInputFocusToWindow (CompWindow *w); - -void -updateWindowSize (CompWindow *w); - -void -raiseWindow (CompWindow *w); - -void -lowerWindow (CompWindow *w); - -void -restackWindowAbove (CompWindow *w, - CompWindow *sibling); - -void -restackWindowBelow (CompWindow *w, - CompWindow *sibling); - -void -updateWindowAttributes (CompWindow *w, - CompStackingUpdateMode stackingMode); - -void -activateWindow (CompWindow *w); - -void -closeWindow (CompWindow *w, - Time serverTime); - -Bool -constrainNewWindowSize (CompWindow *w, - int width, - int height, - int *newWidth, - int *newHeight); - -void -hideWindow (CompWindow *w); - -void -showWindow (CompWindow *w); - -void -minimizeWindow (CompWindow *w); - -void -unminimizeWindow (CompWindow *w); - -void -maximizeWindow (CompWindow *w, - int state); - -Bool -getWindowUserTime (CompWindow *w, - Time *time); - -void -setWindowUserTime (CompWindow *w, - Time time); - -Bool -allowWindowFocus (CompWindow *w, - unsigned int noFocusMask, - Time timestamp); - -void -unredirectWindow (CompWindow *w); - -void -redirectWindow (CompWindow *w); - -void -defaultViewportForWindow (CompWindow *w, - int *vx, - int *vy); - -CompIcon * -getWindowIcon (CompWindow *w, - int width, - int height); - -void -freeWindowIcons (CompWindow *w); - -int -outputDeviceForWindow (CompWindow *w); - -Bool -onCurrentDesktop (CompWindow *w); - -void -setDesktopForWindow (CompWindow *w, - unsigned int desktop); - -int -compareWindowActiveness (CompWindow *w1, - CompWindow *w2); - -Bool -windowOnAllViewports (CompWindow *w); - -void -getWindowMovementForOffset (CompWindow *w, - int offX, - int offY, - int *retX, - int *retY); - /* plugin.c */ #define HOME_PLUGINDIR ".compiz/plugins" @@ -3266,7 +1602,7 @@ void initFragmentAttrib (FragmentAttrib *attrib, const WindowPaintAttrib *paint); -Bool +bool enableFragmentAttrib (CompScreen *s, FragmentAttrib *attrib, Bool *blending); @@ -3315,9 +1651,6 @@ matrixGetIdentity (CompTransform *m); /* cursor.c */ -void -addCursor (CompScreen *s); - Bool damageCursorRect (CompCursor *c, Bool initial, @@ -3400,9 +1733,9 @@ matchPropertyChanged (CompDisplay *display, #define RESTOSTRING(min, max) MINTOSTRING (min) MAXTOSTRING (max) typedef struct _CompMetadataOptionInfo { - char *name; - char *type; - char *data; + const char *name; + const char *type; + const char *data; CompActionCallBackProc initiate; CompActionCallBackProc terminate; } CompMetadataOptionInfo; @@ -3511,4 +1844,10 @@ compReadXmlChunkFromMetadataOptionInfo (const CompMetadataOptionInfo *info, COMPIZ_END_DECLS +#include <compobject.h> +#include <compcore.h> +#include <compdisplay.h> +#include <compscreen.h> +#include <compwindow.h> + #endif diff --git a/include/compiz.h b/include/compiz.h index cc73797..ca50395 100644 --- a/include/compiz.h +++ b/include/compiz.h @@ -38,16 +38,18 @@ typedef int CompWatchFdHandle; typedef union _CompOptionValue CompOptionValue; -typedef struct _CompObject CompObject; -typedef struct _CompCore CompCore; -typedef struct _CompDisplay CompDisplay; typedef struct _CompMetadata CompMetadata; typedef struct _CompOption CompOption; typedef struct _CompPlugin CompPlugin; -typedef struct _CompScreen CompScreen; -typedef struct _CompWindow CompWindow; -typedef CompBool (*CallBackProc) (void *closure); + +class CompCore; +class CompDisplay; +class CompScreen; +class CompWindow; +class CompObject; + +typedef bool (*CallBackProc) (void *closure); typedef enum { CompOptionTypeBool, @@ -119,27 +121,6 @@ CompBool compSetOption (CompOption *option, CompOptionValue *value); -CompTimeoutHandle -compAddTimeout (int minTime, - int maxTime, - CallBackProc callBack, - void *closure); - -void * -compRemoveTimeout (CompTimeoutHandle handle); - -CompWatchFdHandle -compAddWatchFd (int fd, - short int events, - CallBackProc callBack, - void *closure); - -void -compRemoveWatchFd (CompWatchFdHandle handle); - -short int -compWatchFdEvents (CompWatchFdHandle handle); - CompBool compInitMetadata (CompMetadata *metadata); diff --git a/include/compobject.h b/include/compobject.h new file mode 100644 index 0000000..a95ced7 --- /dev/null +++ b/include/compobject.h @@ -0,0 +1,13 @@ +#ifndef _COMPOBJECT_H +#define _COMPOBJECT_H + +class CompObject { + public : + + CompObjectType type; + CompPrivate *privates; + CompObject *parent; +}; + + +#endif diff --git a/include/compiz-plugin.h b/include/compplugin.h index b8a30f6..f6d69de 100644 --- a/include/compiz-plugin.h +++ b/include/compplugin.h @@ -28,43 +28,51 @@ #include <compiz.h> -COMPIZ_BEGIN_DECLS - -typedef CompBool (*InitPluginProc) (CompPlugin *plugin); -typedef void (*FiniPluginProc) (CompPlugin *plugin); -typedef CompMetadata *(*GetMetadataProc) (CompPlugin *plugin); +typedef bool (*InitPluginObjectProc) (CompObject *object); +typedef void (*FiniPluginObjectProc) (CompObject *object); -typedef CompBool (*InitPluginObjectProc) (CompPlugin *plugin, - CompObject *object); -typedef void (*FiniPluginObjectProc) (CompPlugin *plugin, - CompObject *object); - -typedef CompOption *(*GetPluginObjectOptionsProc) (CompPlugin *plugin, - CompObject *object, +typedef CompOption *(*GetPluginObjectOptionsProc) (CompObject *object, int *count); -typedef CompBool (*SetPluginObjectOptionProc) (CompPlugin *plugin, - CompObject *object, +typedef bool (*SetPluginObjectOptionProc) (CompObject *object, const char *name, CompOptionValue *value); -typedef struct _CompPluginVTable { - const char *name; +class CompPluginVTable { + + public: + virtual ~CompPluginVTable (); + + virtual const char * name () = 0; - GetMetadataProc getMetadata; + virtual CompMetadata * + getMetadata (); - InitPluginProc init; - FiniPluginProc fini; + virtual bool + init () = 0; - InitPluginObjectProc initObject; - FiniPluginObjectProc finiObject; + virtual void + fini () = 0; - GetPluginObjectOptionsProc getObjectOptions; - SetPluginObjectOptionProc setObjectOption; -} CompPluginVTable; + virtual bool + initObject (CompObject *object); + + virtual void + finiObject (CompObject *object); + + virtual CompOption * + getObjectOptions (CompObject *object, int *count); + + virtual bool + setObjectOption (CompObject *object, + const char *name, + CompOptionValue *value); +}; + +COMPIZ_BEGIN_DECLS CompPluginVTable * -getCompPluginInfo20070830 (void); +getCompPluginInfo20080805 (void); COMPIZ_END_DECLS diff --git a/include/compscreen.h b/include/compscreen.h new file mode 100644 index 0000000..67007d4 --- /dev/null +++ b/include/compscreen.h @@ -0,0 +1,554 @@ +#ifndef _COMPSCREEN_H +#define _COMPSCREEN_H + + +class CompScreen; +class PrivateScreen; + +class ScreenInterface : public WrapableInterface<CompScreen> { + public: + ScreenInterface (); + + WRAPABLE_DEF(void, preparePaint, int); + WRAPABLE_DEF(void, donePaint); + WRAPABLE_DEF(void, paint, CompOutput *outputs, int, unsigned int); + + WRAPABLE_DEF(bool, paintOutput, const ScreenPaintAttrib *, + const CompTransform *, Region, CompOutput *, + unsigned int); + WRAPABLE_DEF(void, paintTransformedOutput, const ScreenPaintAttrib *, + const CompTransform *, Region, CompOutput *, + unsigned int); + WRAPABLE_DEF(void, applyTransform, const ScreenPaintAttrib *, + CompOutput *, CompTransform *); + + WRAPABLE_DEF(void, enableOutputClipping, const CompTransform *, + Region, CompOutput *); + WRAPABLE_DEF(void, disableOutputClipping); + + WRAPABLE_DEF(void, enterShowDesktopMode); + WRAPABLE_DEF(void, leaveShowDesktopMode, CompWindow *); + + WRAPABLE_DEF(void, outputChangeNotify); + + WRAPABLE_DEF(void, initWindowWalker, CompWalker *walker); + + WRAPABLE_DEF(void, paintCursor, CompCursor *, const CompTransform *, + Region, unsigned int); + WRAPABLE_DEF(bool, damageCursorRect, CompCursor *, bool, BoxPtr); +}; + + +class CompScreen : public WrapableHandler<ScreenInterface>, public CompObject { + + public: + CompScreen *next; + char *windowPrivateIndices; + int windowPrivateLen; + + + public: + CompScreen (); + ~CompScreen (); + + bool + init (CompDisplay *, int); + + bool + init (CompDisplay *, int, Window, Atom, Time); + + CompDisplay * + display (); + + Window + root (); + + int + screenNum (); + + CompWindow * + windows (); + + CompWindow * + reverseWindows (); + + CompOption * + getOption (const char *name); + + unsigned int + showingDesktopMask (); + + bool + handlePaintTimeout (); + + bool + setOption (const char *name, + CompOptionValue *value); + + void + setCurrentOutput (int outputNum); + + void + configure (XConfigureEvent *ce); + + int + maxGrab (); + + void + warpPointer (int dx, int dy); + + Time + getCurrentTime (); + + Atom + selectionAtom (); + + Window + selectionWindow (); + + Time + selectionTimestamp (); + + CompCursor * + cursors (); + + void + updateWorkareaForScreen (); + + void + setDefaultViewport (); + + void + damageScreen (); + + FuncPtr + getProcAddress (const char *name); + + void + showOutputWindow (); + + void + hideOutputWindow (); + + void + updateOutputWindow (); + + void + damageRegion (Region); + + void + damagePending (); + + void + forEachWindow (ForEachWindowProc, void *); + + void + focusDefaultWindow (); + + CompWindow * + findWindow (Window id); + + CompWindow * + findTopLevelWindow (Window id); + + void + insertWindow (CompWindow *w, Window aboveId); + + void + unhookWindow (CompWindow *w); + + int + pushGrab (Cursor cursor, const char *name); + + void + updateGrab (int index, Cursor cursor); + + void + removeGrab (int index, XPoint *restorePointer); + + bool + otherGrabExist (const char *, ...); + + bool + addAction (CompAction *action); + + void + removeAction (CompAction *action); + + void + updatePassiveGrabs (); + + void + updateWorkarea (); + + void + updateClientList (); + + void + toolkitAction (Atom toolkitAction, + Time eventTime, + Window window, + long data0, + long data1, + long data2); + + void + runCommand (const char *command); + + void + moveViewport (int tx, int ty, bool sync); + + CompGroup * + addGroup (Window id); + + void + removeGroup (CompGroup *group); + + CompGroup * + findGroup (Window id); + + void + applyStartupProperties (CompWindow *window); + + void + sendWindowActivationRequest (Window id); + + void + setTexEnvMode (GLenum mode); + + void + setLighting (bool lighting); + + void + enableEdge (int edge); + + void + disableEdge (int edge); + + Window + getTopWindow (); + + void + makeCurrent (); + + void + finishDrawing (); + + int + outputDeviceForPoint (int x, int y); + + void + getCurrentOutputExtents (int *x1, int *y1, int *x2, int *y2); + + void + setNumberOfDesktops (unsigned int nDesktop); + + void + setCurrentDesktop (unsigned int desktop); + + void + getWorkareaForOutput (int output, XRectangle *area); + + void + clearOutput (CompOutput *output, unsigned int mask); + + void + viewportForGeometry (int x, + int y, + int width, + int height, + int borderWidth, + int *viewportX, + int *viewportY); + + int + outputDeviceForGeometry (int x, + int y, + int width, + int height, + int borderWidth); + + bool + updateDefaultIcon (); + + CompCursor * + findCursor (); + + CompCursorImage * + findCursorImage (unsigned long serial); + + void + setCurrentActiveWindowHistory (int x, int y); + + void + addToCurrentActiveWindowHistory (Window id); + + void + setWindowPaintOffset (int x, int y); + + int + getTimeToNextRedraw (struct timeval *tv); + + void + waitForVideoSync (); + + int + maxTextureSize (); + + unsigned int + damageMask (); + + int + x (); + + int + y (); + + int + vsize (); + + int + hsize (); + + int + width (); + + int + height (); + + unsigned int & + pendingDestroys (); + + unsigned int & + mapNum (); + + int & + desktopWindowCount (); + + int & + overlayWindowCount (); + + CompOutput * + outputDev (); + + int + nOutputDev (); + + XRectangle + workArea (); + + unsigned int + currentDesktop (); + + unsigned int + nDesktop (); + + CompActiveWindowHistory * + currentHistory (); + + CompScreenEdge & + screenEdge (int); + + Window + overlay (); + + unsigned int & + activeNum (); + + void + handleExposeEvent (XExposeEvent *event); + + void + detectRefreshRate (); + + void + updateBackground (); + + bool + textureNonPowerOfTwo (); + + bool + textureCompression (); + + bool + bindPixmapToTexture (CompTexture *texture, + Pixmap pixmap, + int width, + int height, + int depth); + + bool + canDoSaturated (); + + bool + canDoSlightlySaturated (); + + bool + lighting (); + + int + filter (int); + + CompFunction *& + fragmentFunctions (); + + CompProgram *& + fragmentPrograms (); + + int & + lastFunctionId (); + + int & + getSaturateFunction (int, int); + + bool + fragmentProgram (); + + void + releasePixmapFromTexture (CompTexture *texture); + + void + enableTexture (CompTexture *texture, + CompTextureFilter filter); + + void + disableTexture (CompTexture *texture); + + void + addCursor (); + + CompCursorImage *& + cursorImages (); + + WRAPABLE_HND(void, preparePaint, int); + WRAPABLE_HND(void, donePaint); + WRAPABLE_HND(void, paint, CompOutput *outputs, int, unsigned int); + + WRAPABLE_HND(bool, paintOutput, const ScreenPaintAttrib *, + const CompTransform *, Region, CompOutput *, + unsigned int); + WRAPABLE_HND(void, paintTransformedOutput, const ScreenPaintAttrib *, + const CompTransform *, Region, CompOutput *, + unsigned int); + WRAPABLE_HND(void, applyTransform, const ScreenPaintAttrib *, + CompOutput *, CompTransform *); + + WRAPABLE_HND(void, enableOutputClipping, const CompTransform *, + Region, CompOutput *); + WRAPABLE_HND(void, disableOutputClipping); + + WRAPABLE_HND(void, enterShowDesktopMode); + WRAPABLE_HND(void, leaveShowDesktopMode, CompWindow *); + + WRAPABLE_HND(void, outputChangeNotify); + + WRAPABLE_HND(void, initWindowWalker, CompWalker *walker); + + WRAPABLE_HND(void, paintCursor, CompCursor *, const CompTransform *, + Region, unsigned int); + WRAPABLE_HND(bool, damageCursorRect, CompCursor *, bool, BoxPtr); + + GLXBindTexImageProc bindTexImage; + GLXReleaseTexImageProc releaseTexImage; + GLXQueryDrawableProc queryDrawable; + GLXCopySubBufferProc copySubBuffer; + GLXGetVideoSyncProc getVideoSync; + GLXWaitVideoSyncProc waitVideoSync; + GLXGetFBConfigsProc getFBConfigs; + GLXGetFBConfigAttribProc getFBConfigAttrib; + GLXCreatePixmapProc createPixmap; + + GLActiveTextureProc activeTexture; + GLClientActiveTextureProc clientActiveTexture; + GLMultiTexCoord2fProc multiTexCoord2f; + + GLGenProgramsProc genPrograms; + GLDeleteProgramsProc deletePrograms; + GLBindProgramProc bindProgram; + GLProgramStringProc programString; + GLProgramParameter4fProc programEnvParameter4f; + GLProgramParameter4fProc programLocalParameter4f; + GLGetProgramivProc getProgramiv; + + GLGenFramebuffersProc genFramebuffers; + GLDeleteFramebuffersProc deleteFramebuffers; + GLBindFramebufferProc bindFramebuffer; + GLCheckFramebufferStatusProc checkFramebufferStatus; + GLFramebufferTexture2DProc framebufferTexture2D; + GLGenerateMipmapProc generateMipmap; + + private: + PrivateScreen *priv; + + public : + static bool + mainMenu (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + runDialog (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + showDesktop (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + toggleSlowAnimations (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + windowMenu (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static CompOption * + getScreenOptions ( CompObject *object, + int *count); + + static bool + startupSequenceTimeout (void *data); + + static void + compScreenSnEvent (SnMonitorEvent *event, + void *userData); +}; + +bool +paintTimeout (void *closure); + +int +getTimeToNextRedraw (CompScreen *s, + struct timeval *tv, + struct timeval *lastTv, + Bool idle); + +void +waitForVideoSync (CompScreen *s); + +Bool +initScreen (CompScreen *s, + CompDisplay *display, + int screenNum, + Window wmSnSelectionWindow, + Atom wmSnAtom, + Time wmSnTimestamp); + +void +finiScreen (CompScreen *s); + +#endif diff --git a/include/compwindow.h b/include/compwindow.h new file mode 100644 index 0000000..d4d4f32 --- /dev/null +++ b/include/compwindow.h @@ -0,0 +1,563 @@ +#ifndef _COMPWINDOW_H +#define _COMPWINDOW_H + +class CompWindow; +class PrivateWindow; + +class WindowInterface : public WrapableInterface<CompWindow> { + public: + WindowInterface (); + + WRAPABLE_DEF(bool, paint, const WindowPaintAttrib *, + const CompTransform *, Region, unsigned int); + WRAPABLE_DEF(bool, draw, const CompTransform *, + const FragmentAttrib *, Region, unsigned int); + WRAPABLE_DEF(void, addGeometry, CompMatrix *matrix, + int, Region, Region); + WRAPABLE_DEF(void, drawTexture, CompTexture *texture, + const FragmentAttrib *, unsigned int); + WRAPABLE_DEF(void, drawGeometry); + WRAPABLE_DEF(bool, damageRect, bool, BoxPtr); + + WRAPABLE_DEF(void, getOutputExtents, CompWindowExtents *); + WRAPABLE_DEF(void, getAllowedActions, unsigned int *, + unsigned int *); + + WRAPABLE_DEF(bool, focus); + WRAPABLE_DEF(void, activate); + WRAPABLE_DEF(bool, place, int, int, int*, int*); + WRAPABLE_DEF(void, validateResizeRequest, + unsigned int *, XWindowChanges *); + + WRAPABLE_DEF(void, resizeNotify, int, int, int, int); + WRAPABLE_DEF(void, moveNotify, int, int, bool); + WRAPABLE_DEF(void, grabNotify, int, int, + unsigned int, unsigned int); + WRAPABLE_DEF(void, ungrabNotify); + WRAPABLE_DEF(void, stateChangeNotify, unsigned int); + +}; + +class CompWindow : public WrapableHandler<WindowInterface>, public CompObject { + + public: + CompWindow *next; + CompWindow *prev; + + public: + + CompWindow (CompScreen *screen, + Window id, + Window aboveId); + ~CompWindow (); + + CompScreen * + screen (); + + Window + id (); + + Window + frame (); + + unsigned int & + wmType (); + + unsigned int + type (); + + unsigned int & + state (); + + unsigned int + actions (); + + unsigned int & + protocols (); + + XWindowAttributes + attrib (); + + void + close (Time serverTime); + + bool + handlePingTimeout (int lastPing); + + void + handlePing (int lastPing); + + bool + overlayWindow (); + + Region + region (); + + bool + inShowDesktopMode (); + + void + setShowDesktopMode (bool); + + bool & + managed (); + + bool + grabbed (); + + unsigned int & + activeNum (); + + void + setActiveNum (int); + + int + mapNum (); + + CompStruts * + struts (); + + int & + saveMask (); + + XWindowChanges & + saveWc (); + + void + moveToViewportPosition (int x, int y, bool sync); + + char * + startupId (); + + void + applyStartupProperties (CompStartupSequence *s); + + unsigned int + desktop (); + + Window & + clientLeader (); + + void + updateNormalHints (); + + void + updateWmHints (); + + void + updateClassHints (); + + void + updateTransientHint (); + + void + updateIconGeometry (); + + Window + getClientLeader (); + + char * + getStartupId (); + + void + changeState (unsigned int newState); + + void + recalcActions (); + + void + recalcType (); + + void + setWindowFrameExtents (CompWindowExtents *input); + + void + updateWindowOutputExtents (); + + bool + bind (); + + void + release (); + + void + damageTransformedRect (float xScale, + float yScale, + float xTranslate, + float yTranslate, + BoxPtr rect); + + void + damageOutputExtents (); + + void + addDamageRect (BoxPtr rect); + + void + addDamage (); + + void + updateRegion (); + + bool + updateStruts (); + + void + destroy (); + + void + sendConfigureNotify (); + + void + map (); + + void + unmap (); + + bool + resize (int x, int y, int width, int height, int borderWidth); + + bool + handleSyncAlarm (); + + void + sendSyncRequest (); + + void + configure (XConfigureEvent *ce); + + void + circulate (XCirculateEvent *ce); + + void + move (int dx, int dy, Bool damage, Bool immediate); + + void + syncPosition (); + + void + moveInputFocusTo (); + + void + moveInputFocusToOtherWindow (); + + void + configureXWindow (unsigned int valueMask, + XWindowChanges *xwc); + + + unsigned int + adjustConfigureRequestForGravity (XWindowChanges *xwc, + unsigned int xwcm, + int gravity); + + void + moveResize (XWindowChanges *xwc, + unsigned int xwcm, + int gravity); + + void + updateSize (); + + void + raise (); + + void + lower (); + + void + restackAbove (CompWindow *sibling); + + void + restackBelow (CompWindow *sibling); + + void + updateAttributes (CompStackingUpdateMode stackingMode); + + void + hide (); + + void + show (); + + void + minimize (); + + void + unminimize (); + + void + maximize (int state); + + bool + getUserTime (Time *time); + + void + setUserTime (Time time); + + bool + allowWindowFocus (unsigned int noFocusMask, + Time timestamp); + + void + unredirect (); + + void + redirect (); + + void + defaultViewport (int *vx, int *vy); + + CompIcon * + getIcon (int width, int height); + + void + freeIcons (); + + int + outputDevice (); + + bool + onCurrentDesktop (); + + void + setDesktop (unsigned int desktop); + + bool + onAllViewports (); + + void + getMovementForOffset (int offX, + int offY, + int *retX, + int *retY); + + Window + transientFor (); + + int & + pendingUnmaps (); + + bool & + minimized (); + + bool & + placed (); + + bool + shaded (); + + int + height (); + + int + width (); + + int & + serverX (); + + int & + serverY (); + + int + serverWidth (); + + int + serverHeight (); + + int + serverBorderWidth (); + + CompWindowExtents + input (); + + XSizeHints + sizeHints (); + + void + updateOpacity (); + + void + updateBrightness (); + + void + updateSaturation (); + + void + updateMwmHints (); + + void + updateStartupId (); + + void + processMap (); + + void + processDamage (XDamageNotifyEvent *de); + + XSyncAlarm + syncAlarm (); + + bool + destroyed (); + + bool + damaged (); + + bool + invisible (); + + bool + redirected (); + + Region + clip (); + + WindowPaintAttrib & + paintAttrib (); + + bool + moreVertices (int newSize); + + bool + moreIndices (int newSize); + + static unsigned int + constrainWindowState (unsigned int state, + unsigned int actions); + + static unsigned int + windowTypeFromString (const char *str); + + static int + compareWindowActiveness (CompWindow *w1, + CompWindow *w2); + + WRAPABLE_HND(bool, paint, const WindowPaintAttrib *, + const CompTransform *, Region, unsigned int); + WRAPABLE_HND(bool, draw, const CompTransform *, + const FragmentAttrib *, Region, unsigned int); + WRAPABLE_HND(void, addGeometry, CompMatrix *matrix, + int, Region, Region); + WRAPABLE_HND(void, drawTexture, CompTexture *texture, + const FragmentAttrib *, unsigned int); + WRAPABLE_HND(void, drawGeometry); + + + WRAPABLE_HND(bool, damageRect, bool, BoxPtr); + + WRAPABLE_HND(void, getOutputExtents, CompWindowExtents *); + WRAPABLE_HND(void, getAllowedActions, unsigned int *, + unsigned int *); + + WRAPABLE_HND(bool, focus); + WRAPABLE_HND(void, activate); + WRAPABLE_HND(bool, place, int, int, int*, int*); + WRAPABLE_HND(void, validateResizeRequest, + unsigned int *, XWindowChanges *); + + WRAPABLE_HND(void, resizeNotify, int, int, int, int); + WRAPABLE_HND(void, moveNotify, int, int, bool); + WRAPABLE_HND(void, grabNotify, int, int, + unsigned int, unsigned int); + WRAPABLE_HND(void, ungrabNotify); + WRAPABLE_HND(void, stateChangeNotify, unsigned int); + + friend class PrivateWindow; + + private: + PrivateWindow *priv; + + + public: + + // static action functions + static bool + closeWin (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + unmaximize (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + minimize (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + maximize (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + maximizeHorizontally (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + maximizeVertically (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + raiseInitiate (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + lowerInitiate (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + toggleMaximized (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + + static bool + toggleMaximizedHorizontally (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + toggleMaximizedVertically (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + static bool + shade (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption); + + +}; + +#endif diff --git a/metadata/core.xml.in b/metadata/core.xml.in index b32d97b..9475bc0 100644 --- a/metadata/core.xml.in +++ b/metadata/core.xml.in @@ -231,17 +231,7 @@ <_short>Maximize Window Vertically</_short> <_long>Maximize active window vertically</_long> </option> - <option name="opacity_increase_button" type="button"> - <_short>Increase Opacity</_short> - <_long>Increase window opacity</_long> - <default><Alt>Button4</default> - </option> - <option name="opacity_decrease_button" type="button"> - <_short>Decrease Opacity</_short> - <_long>Decrease window opacity</_long> - <default><Alt>Button5</default> - </option> - <option name="command_screenshot" type="string"> + <option name="command_screenshot" type="string"> <_short>Screenshot command line</_short> <_long>Screenshot command line</_long> <default>gnome-screenshot</default> @@ -371,13 +361,6 @@ <min>1</min> <max>32</max> </option> - <option name="opacity_step" type="int"> - <_short>Opacity Step</_short> - <_long>Opacity change step</_long> - <default>10</default> - <min>1</min> - <max>50</max> - </option> <option name="unredirect_fullscreen_windows" type="bool"> <_short>Unredirect Fullscreen Windows</_short> <_long>Allow drawing of fullscreen windows to not be redirected to offscreen pixmaps</_long> @@ -465,18 +448,6 @@ <_long>Focus prevention windows</_long> <default>any</default> </option> - <option name="opacity_matches" type="list"> - <_short>Opacity windows</_short> - <_long>Windows that should be translucent by default</_long> - <type>match</type> - </option> - <option name="opacity_values" type="list"> - <_short>Opacity window values</_short> - <_long>Opacity values for windows that should be translucent by default</_long> - <type>int</type> - <min>0</min> - <max>100</max> - </option> <option name="texture_compression" type="bool"> <_short>Texture Compression</_short> <_long>If available use compression for textures converted from images</_long> diff --git a/plugins/Makefile.am b/plugins/Makefile.am index ce90a87..94055f7 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -145,14 +145,17 @@ INCLUDES = \ moduledir = $(plugindir) module_LTLIBRARIES = \ - $(libglib_module) \ - $(libgconf_module) \ - $(libkconfig_module) \ - libdecoration.la \ - libzoom.la \ - libmove.la \ - libresize.la -# + libmove.la + + +#module_LTLIBRARIES = \ +# $(libglib_module) \ +# $(libgconf_module) \ +# $(libkconfig_module) \ +# libdecoration.la \ +# libzoom.la \ +# libmove.la \ +# libresize.la \ # libwobbly.la \ # libfade.la \ # libminimize.la \ diff --git a/plugins/move.cpp b/plugins/move.cpp index 37af8d0..6772bc3 100644 --- a/plugins/move.cpp +++ b/plugins/move.cpp @@ -33,6 +33,39 @@ static CompMetadata moveMetadata; +class MovePluginVTable : public CompPluginVTable +{ + public: + + const char * + name () { return "move"; }; + + CompMetadata * + getMetadata (); + + virtual bool + init (); + + virtual void + fini (); + + virtual bool + initObject (CompObject *object); + + virtual void + finiObject (CompObject *object); + + CompOption * + getObjectOptions (CompObject *object, int *count); + + bool + setObjectOption (CompObject *object, + const char *name, + CompOptionValue *value); +}; + + + struct _MoveKeys { char *name; int dx; @@ -61,54 +94,95 @@ static int displayPrivateIndex; #define MOVE_DISPLAY_OPTION_LAZY_POSITIONING 5 #define MOVE_DISPLAY_OPTION_NUM 6 -typedef struct _MoveDisplay { - int screenPrivateIndex; - HandleEventProc handleEvent; +class MoveDisplay : public DisplayInterface { - CompOption opt[MOVE_DISPLAY_OPTION_NUM]; + public: + MoveDisplay (CompDisplay *display) : display (display) + { + display->add (this); + DisplayInterface::setHandler (display); + }; - CompWindow *w; - int savedX; - int savedY; - int x; - int y; - Region region; - int status; - KeyCode key[NUM_KEYS]; + void + handleEvent (XEvent *); + + + CompDisplay *display; + int screenPrivateIndex; + + + CompOption opt[MOVE_DISPLAY_OPTION_NUM]; - int releaseButton; + CompWindow *w; + int savedX; + int savedY; + int x; + int y; + Region region; + int status; + KeyCode key[NUM_KEYS]; + + int releaseButton; + + GLushort moveOpacity; +}; + + + +class MoveScreen { + public: + + MoveScreen (CompScreen *screen) : screen (screen) {}; + + int windowPrivateIndex; + + CompScreen *screen; + int grabIndex; - GLushort moveOpacity; -} MoveDisplay; + Cursor moveCursor; -typedef struct _MoveScreen { - PaintWindowProc paintWindow; + unsigned int origState; - int grabIndex; + int snapOffY; + int snapBackY; +}; - Cursor moveCursor; +class MoveWindow : public WindowInterface { + public: + MoveWindow (CompWindow *window) : window (window) + { + window->add (this); + WindowInterface::setHandler (window); + }; - unsigned int origState; + bool + paint (const WindowPaintAttrib *, const CompTransform *, Region, + unsigned int); - int snapOffY; - int snapBackY; -} MoveScreen; + CompWindow *window; +}; #define GET_MOVE_DISPLAY(d) \ - ((MoveDisplay *) (d)->base.privates[displayPrivateIndex].ptr) + ((MoveDisplay *) (d)->privates[displayPrivateIndex].ptr) #define MOVE_DISPLAY(d) \ MoveDisplay *md = GET_MOVE_DISPLAY (d) #define GET_MOVE_SCREEN(s, md) \ - ((MoveScreen *) (s)->base.privates[(md)->screenPrivateIndex].ptr) + ((MoveScreen *) (s)->privates[(md)->screenPrivateIndex].ptr) #define MOVE_SCREEN(s) \ - MoveScreen *ms = GET_MOVE_SCREEN (s, GET_MOVE_DISPLAY (s->display)) + MoveScreen *ms = GET_MOVE_SCREEN (s, GET_MOVE_DISPLAY (s->display ())) + +#define GET_MOVE_WINDOW(w, ms) \ + ((MoveWindow *) (w)->privates[(ms)->windowPrivateIndex].ptr) + +#define MOVE_WINDOW(w) \ + MoveWindow *mw = GET_MOVE_WINDOW (w, GET_MOVE_SCREEN (w->screen (), GET_MOVE_DISPLAY (w->screen ()->display()))) #define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption)) -static Bool +static bool moveInitiate (CompDisplay *d, CompAction *action, CompActionState state, @@ -122,36 +196,38 @@ moveInitiate (CompDisplay *d, xid = getIntOptionNamed (option, nOption, "window", 0); - w = findWindowAtDisplay (d, xid); - if (w && (w->actions & CompWindowActionMoveMask)) + w = d->findWindow (xid); + if (w && (w->actions () & CompWindowActionMoveMask)) { XRectangle workArea; unsigned int mods; int x, y, button; - MOVE_SCREEN (w->screen); + CompScreen *s = w->screen (); + + MOVE_SCREEN (w->screen ()); mods = getIntOptionNamed (option, nOption, "modifiers", 0); x = getIntOptionNamed (option, nOption, "x", - w->attrib.x + (w->width / 2)); + w->attrib ().x + (w->width () / 2)); y = getIntOptionNamed (option, nOption, "y", - w->attrib.y + (w->height / 2)); + w->attrib ().y + (w->height () / 2)); button = getIntOptionNamed (option, nOption, "button", -1); - if (otherScreenGrabExist (w->screen, "move", 0)) + if (s->otherGrabExist ("move", 0)) return FALSE; if (md->w) return FALSE; - if (w->type & (CompWindowTypeDesktopMask | + if (w->type () & (CompWindowTypeDesktopMask | CompWindowTypeDockMask | CompWindowTypeFullscreenMask)) return FALSE; - if (w->attrib.override_redirect) + if (w->attrib ().override_redirect) return FALSE; if (state & CompActionStateInitButton) @@ -165,8 +241,8 @@ moveInitiate (CompDisplay *d, md->status = RectangleOut; - md->savedX = w->serverX; - md->savedY = w->serverY; + md->savedX = w->serverX (); + md->savedY = w->serverY (); md->x = 0; md->y = 0; @@ -174,17 +250,16 @@ moveInitiate (CompDisplay *d, lastPointerX = x; lastPointerY = y; - ms->origState = w->state; + ms->origState = w->state (); - getWorkareaForOutput (w->screen, - outputDeviceForWindow (w), - &workArea); + s->getWorkareaForOutput (w->outputDevice (), + &workArea); - ms->snapBackY = w->serverY - workArea.y; + ms->snapBackY = w->serverY () - workArea.y; ms->snapOffY = y - workArea.y; if (!ms->grabIndex) - ms->grabIndex = pushScreenGrab (w->screen, ms->moveCursor, "move"); + ms->grabIndex = s->pushGrab (ms->moveCursor, "move"); if (ms->grabIndex) { @@ -192,29 +267,28 @@ moveInitiate (CompDisplay *d, md->releaseButton = button; - (w->screen->windowGrabNotify) (w, x, y, mods, - CompWindowGrabMoveMask | - CompWindowGrabButtonMask); + w->grabNotify (x, y, mods,CompWindowGrabMoveMask | + CompWindowGrabButtonMask); if (state & CompActionStateInitKey) { int xRoot, yRoot; - xRoot = w->attrib.x + (w->width / 2); - yRoot = w->attrib.y + (w->height / 2); + xRoot = w->attrib ().x + (w->width () / 2); + yRoot = w->attrib ().y + (w->height () / 2); - warpPointer (w->screen, xRoot - pointerX, yRoot - pointerY); + s->warpPointer (xRoot - pointerX, yRoot - pointerY); } if (md->moveOpacity != OPAQUE) - addWindowDamage (w); + w->addDamage (); } } return FALSE; } -static Bool +static bool moveTerminate (CompDisplay *d, CompAction *action, CompActionState state, @@ -225,31 +299,30 @@ moveTerminate (CompDisplay *d, if (md->w) { - MOVE_SCREEN (md->w->screen); + MOVE_SCREEN (md->w->screen ()); if (state & CompActionStateCancel) - moveWindow (md->w, - md->savedX - md->w->attrib.x, - md->savedY - md->w->attrib.y, + md->w->move (md->savedX - md->w->attrib ().x, + md->savedY - md->w->attrib ().y, TRUE, FALSE); - syncWindowPosition (md->w); + md->w->syncPosition (); /* update window attributes as window constraints may have changed - needed e.g. if a maximized window was moved to another output device */ - updateWindowAttributes (md->w, CompStackingUpdateModeNone); + md->w->updateAttributes (CompStackingUpdateModeNone); - (md->w->screen->windowUngrabNotify) (md->w); + md->w->ungrabNotify (); if (ms->grabIndex) { - removeScreenGrab (md->w->screen, ms->grabIndex, NULL); + md->w->screen ()->removeGrab (ms->grabIndex, NULL); ms->grabIndex = 0; } if (md->moveOpacity != OPAQUE) - addWindowDamage (md->w); + md->w->addDamage (); md->w = 0; md->releaseButton = 0; @@ -282,33 +355,33 @@ moveGetYConstrainRegion (CompScreen *s) r.extents.x1 = MINSHORT; r.extents.y1 = 0; r.extents.x2 = 0; - r.extents.y2 = s->height; + r.extents.y2 = s->height (); XUnionRegion (&r, region, region); - r.extents.x1 = s->width; + r.extents.x1 = s->width (); r.extents.x2 = MAXSHORT; XUnionRegion (&r, region, region); - for (i = 0; i < s->nOutputDev; i++) + for (i = 0; i < s->nOutputDev (); i++) { - XUnionRegion (&s->outputDev[i].region, region, region); + XUnionRegion (&s->outputDev ()[i].region, region, region); - getWorkareaForOutput (s, i, &workArea); - extents = s->outputDev[i].region.extents; + s->getWorkareaForOutput (i, &workArea); + extents = s->outputDev ()[i].region.extents; - for (w = s->windows; w; w = w->next) + for (w = s->windows (); w; w = w->next) { - if (!w->mapNum) + if (!w->mapNum ()) continue; - if (w->struts) + if (w->struts ()) { - r.extents.x1 = w->struts->top.x; - r.extents.y1 = w->struts->top.y; - r.extents.x2 = r.extents.x1 + w->struts->top.width; - r.extents.y2 = r.extents.y1 + w->struts->top.height; + r.extents.x1 = w->struts ()->top.x; + r.extents.y1 = w->struts ()->top.y; + r.extents.x2 = r.extents.x1 + w->struts ()->top.width; + r.extents.y2 = r.extents.y1 + w->struts ()->top.height; if (r.extents.x1 < extents.x1) r.extents.x1 = extents.x1; @@ -325,10 +398,10 @@ moveGetYConstrainRegion (CompScreen *s) XSubtractRegion (region, &r, region); } - r.extents.x1 = w->struts->bottom.x; - r.extents.y1 = w->struts->bottom.y; - r.extents.x2 = r.extents.x1 + w->struts->bottom.width; - r.extents.y2 = r.extents.y1 + w->struts->bottom.height; + r.extents.x1 = w->struts ()->bottom.x; + r.extents.y1 = w->struts ()->bottom.y; + r.extents.x2 = r.extents.x1 + w->struts ()->bottom.width; + r.extents.y2 = r.extents.y1 + w->struts ()->bottom.height; if (r.extents.x1 < extents.x1) r.extents.x1 = extents.x1; @@ -360,24 +433,24 @@ moveHandleMotionEvent (CompScreen *s, if (ms->grabIndex) { - CompWindow *w; int dx, dy; int wX, wY; int wWidth, wHeight; + CompWindow *w; - MOVE_DISPLAY (s->display); + MOVE_DISPLAY (s->display ()); w = md->w; - - wX = w->serverX; - wY = w->serverY; - wWidth = w->serverWidth + w->serverBorderWidth * 2; - wHeight = w->serverHeight + w->serverBorderWidth * 2; + + wX = w->serverX (); + wY = w->serverY (); + wWidth = w->serverWidth () + w->serverBorderWidth () * 2; + wHeight = w->serverHeight () + w->serverBorderWidth () * 2; md->x += xRoot - lastPointerX; md->y += yRoot - lastPointerY; - if (w->type & CompWindowTypeFullscreenMask) + if (w->type () & CompWindowTypeFullscreenMask) { dx = dy = 0; } @@ -389,9 +462,7 @@ moveHandleMotionEvent (CompScreen *s, dx = md->x; dy = md->y; - getWorkareaForOutput (s, - outputDeviceForWindow (w), - &workArea); + s->getWorkareaForOutput (w->outputDevice (), &workArea); if (md->opt[MOVE_DISPLAY_OPTION_CONSTRAIN_Y].value.b) { @@ -406,10 +477,10 @@ moveHandleMotionEvent (CompScreen *s, int x, y, width, height; int status; - x = wX + dx - w->input.left; - y = wY + dy - w->input.top; - width = wWidth + w->input.left + w->input.right; - height = w->input.top ? w->input.top : 1; + x = wX + dx - w->input ().left; + y = wY + dy - w->input ().top; + width = wWidth + w->input ().left + w->input ().right; + height = w->input ().top ? w->input ().top : 1; status = XRectInRegion (md->region, x, y, width, height); @@ -427,7 +498,7 @@ moveHandleMotionEvent (CompScreen *s, if (xStatus != RectangleIn) dx += (dx < 0) ? 1 : -1; - x = wX + dx - w->input.left; + x = wX + dx - w->input ().left; } while (dy && status != RectangleIn) @@ -439,7 +510,7 @@ moveHandleMotionEvent (CompScreen *s, if (status != RectangleIn) dy += (dy < 0) ? 1 : -1; - y = wY + dy - w->input.top; + y = wY + dy - w->input ().top; } } else @@ -451,25 +522,25 @@ moveHandleMotionEvent (CompScreen *s, if (md->opt[MOVE_DISPLAY_OPTION_SNAPOFF_MAXIMIZED].value.b) { - if (w->state & CompWindowStateMaximizedVertMask) + if (w->state () & CompWindowStateMaximizedVertMask) { if (abs ((yRoot - workArea.y) - ms->snapOffY) >= SNAP_OFF) { - if (!otherScreenGrabExist (s, "move", 0)) + if (!s->otherGrabExist ("move", 0)) { - int width = w->serverWidth; + int width = w->serverWidth (); - w->saveMask |= CWX | CWY; + w->saveMask () |= CWX | CWY; - if (w->saveMask & CWWidth) - width = w->saveWc.width; + if (w->saveMask ()& CWWidth) + width = w->saveWc ().width; - w->saveWc.x = xRoot - (width >> 1); - w->saveWc.y = yRoot + (w->input.top >> 1); + w->saveWc ().x = xRoot - (width >> 1); + w->saveWc ().y = yRoot + (w->input ().top >> 1); md->x = md->y = 0; - maximizeWindow (w, 0); + w->maximize (0); ms->snapOffY = ms->snapBackY; @@ -481,21 +552,21 @@ moveHandleMotionEvent (CompScreen *s, { if (abs ((yRoot - workArea.y) - ms->snapBackY) < SNAP_BACK) { - if (!otherScreenGrabExist (s, "move", 0)) + if (!s->otherGrabExist ("move", 0)) { int wy; /* update server position before maximizing window again so that it is maximized on correct output */ - syncWindowPosition (w); + w->syncPosition (); - maximizeWindow (w, ms->origState); + w->maximize (ms->origState); - wy = workArea.y + (w->input.top >> 1); - wy += w->sizeHints.height_inc >> 1; + wy = workArea.y + (w->input ().top >> 1); + wy += w->sizeHints ().height_inc >> 1; - warpPointer (s, 0, wy - pointerY); + s->warpPointer (0, wy - pointerY); return; } @@ -503,10 +574,10 @@ moveHandleMotionEvent (CompScreen *s, } } - if (w->state & CompWindowStateMaximizedVertMask) + if (w->state () & CompWindowStateMaximizedVertMask) { - min = workArea.y + w->input.top; - max = workArea.y + workArea.height - w->input.bottom - wHeight; + min = workArea.y + w->input ().top; + max = workArea.y + workArea.height - w->input ().bottom - wHeight; if (wY + dy < min) dy = min - wY; @@ -514,16 +585,16 @@ moveHandleMotionEvent (CompScreen *s, dy = max - wY; } - if (w->state & CompWindowStateMaximizedHorzMask) + if (w->state () & CompWindowStateMaximizedHorzMask) { - if (wX > s->width || wX + w->width < 0) + if (wX > s->width () || wX + w->width () < 0) return; if (wX + wWidth < 0) return; - min = workArea.x + w->input.left; - max = workArea.x + workArea.width - w->input.right - wWidth; + min = workArea.x + w->input ().left; + max = workArea.x + workArea.width - w->input ().right - wWidth; if (wX + dx < min) dx = min - wX; @@ -534,9 +605,8 @@ moveHandleMotionEvent (CompScreen *s, if (dx || dy) { - moveWindow (w, - wX + dx - w->attrib.x, - wY + dy - w->attrib.y, + w->move (wX + dx - w->attrib ().x, + wY + dy - w->attrib ().y, TRUE, FALSE); if (md->opt[MOVE_DISPLAY_OPTION_LAZY_POSITIONING].value.b) @@ -544,12 +614,12 @@ moveHandleMotionEvent (CompScreen *s, /* FIXME: This form of lazy positioning is broken and should be replaced asap. Current code exists just to avoid a major performance regression in the 0.5.2 release. */ - w->serverX = w->attrib.x; - w->serverY = w->attrib.y; + w->serverX () = w->attrib ().x; + w->serverY () = w->attrib ().y; } else { - syncWindowPosition (w); + w->syncPosition (); } md->x -= dx; @@ -558,39 +628,35 @@ moveHandleMotionEvent (CompScreen *s, } } -static void -moveHandleEvent (CompDisplay *d, - XEvent *event) +void +MoveDisplay::handleEvent (XEvent *event) { CompScreen *s; - MOVE_DISPLAY (d); - switch (event->type) { case ButtonPress: case ButtonRelease: - s = findScreenAtDisplay (d, event->xbutton.root); + s = display->findScreen (event->xbutton.root); if (s) { MOVE_SCREEN (s); if (ms->grabIndex) { - if (md->releaseButton == -1 || - md->releaseButton == event->xbutton.button) + if (releaseButton == -1 || + releaseButton == event->xbutton.button) { CompAction *action; - int opt = MOVE_DISPLAY_OPTION_INITIATE_BUTTON; - action = &md->opt[opt].value.action; - moveTerminate (d, action, CompActionStateTermButton, + action = &opt[MOVE_DISPLAY_OPTION_INITIATE_BUTTON].value.action; + moveTerminate (display, action, CompActionStateTermButton, NULL, 0); } } } break; case KeyPress: - s = findScreenAtDisplay (d, event->xkey.root); + s = display->findScreen (event->xkey.root); if (s) { MOVE_SCREEN (s); @@ -601,9 +667,9 @@ moveHandleEvent (CompDisplay *d, for (i = 0; i < NUM_KEYS; i++) { - if (event->xkey.keycode == md->key[i]) + if (event->xkey.keycode == key[i]) { - XWarpPointer (d->display, None, None, 0, 0, 0, 0, + XWarpPointer (display->dpy (), None, None, 0, 0, 0, 0, mKeys[i].dx * KEY_MOVE_INC, mKeys[i].dy * KEY_MOVE_INC); break; @@ -613,25 +679,25 @@ moveHandleEvent (CompDisplay *d, } break; case MotionNotify: - s = findScreenAtDisplay (d, event->xmotion.root); + s = display->findScreen (event->xmotion.root); if (s) moveHandleMotionEvent (s, pointerX, pointerY); break; case EnterNotify: case LeaveNotify: - s = findScreenAtDisplay (d, event->xcrossing.root); + s = display->findScreen (event->xcrossing.root); if (s) moveHandleMotionEvent (s, pointerX, pointerY); break; case ClientMessage: - if (event->xclient.message_type == d->wmMoveResizeAtom) + if (event->xclient.message_type == display->atoms ().wmMoveResize) { CompWindow *w; if (event->xclient.data.l[2] == WmMoveResizeMove || event->xclient.data.l[2] == WmMoveResizeMoveKeyboard) { - w = findWindowAtDisplay (d, event->xclient.window); + w = display->findWindow (event->xclient.window); if (w) { CompOption o[5]; @@ -646,7 +712,7 @@ moveHandleEvent (CompDisplay *d, { option = MOVE_DISPLAY_OPTION_INITIATE_KEY; - moveInitiate (d, &md->opt[option].value.action, + moveInitiate (display, &opt[option].value.action, CompActionStateInitKey, o, 1); } @@ -658,7 +724,7 @@ moveHandleEvent (CompDisplay *d, option = MOVE_DISPLAY_OPTION_INITIATE_BUTTON; - XQueryPointer (d->display, w->screen->root, + XQueryPointer (display->dpy (), w->screen ()->root (), &root, &child, &xRoot, &yRoot, &i, &i, &mods); @@ -682,12 +748,12 @@ moveHandleEvent (CompDisplay *d, o[4].value.i = event->xclient.data.l[3] ? event->xclient.data.l[3] : -1; - moveInitiate (d, - &md->opt[option].value.action, + moveInitiate (display, + &opt[option].value.action, CompActionStateInitButton, o, 5); - moveHandleMotionEvent (w->screen, xRoot, yRoot); + moveHandleMotionEvent (w->screen (), xRoot, yRoot); } } } @@ -695,61 +761,57 @@ moveHandleEvent (CompDisplay *d, } break; case DestroyNotify: - if (md->w && md->w->id == event->xdestroywindow.window) + if (w && w->id () == event->xdestroywindow.window) { int option; option = MOVE_DISPLAY_OPTION_INITIATE_BUTTON; - moveTerminate (d, - &md->opt[option].value.action, + moveTerminate (display, + &opt[option].value.action, 0, NULL, 0); option = MOVE_DISPLAY_OPTION_INITIATE_KEY; - moveTerminate (d, - &md->opt[option].value.action, + moveTerminate (display, + &opt[option].value.action, 0, NULL, 0); } break; case UnmapNotify: - if (md->w && md->w->id == event->xunmap.window) + if (w && w->id () == event->xunmap.window) { int option; option = MOVE_DISPLAY_OPTION_INITIATE_BUTTON; - moveTerminate (d, - &md->opt[option].value.action, + moveTerminate (display, + &opt[option].value.action, 0, NULL, 0); option = MOVE_DISPLAY_OPTION_INITIATE_KEY; - moveTerminate (d, - &md->opt[option].value.action, + moveTerminate (display, + &opt[option].value.action, 0, NULL, 0); } default: break; } - UNWRAP (md, d, handleEvent); - (*d->handleEvent) (d, event); - WRAP (md, d, handleEvent, moveHandleEvent); + display->handleEvent (event); } -static Bool -movePaintWindow (CompWindow *w, - const WindowPaintAttrib *attrib, - const CompTransform *transform, - Region region, - unsigned int mask) +bool +MoveWindow::paint (const WindowPaintAttrib *attrib, + const CompTransform *transform, + Region region, + unsigned int mask) { WindowPaintAttrib sAttrib; - CompScreen *s = w->screen; - Bool status; + bool status; - MOVE_SCREEN (s); + MOVE_SCREEN (window->screen ()); if (ms->grabIndex) { - MOVE_DISPLAY (s->display); + MOVE_DISPLAY (window->screen ()->display ()); - if (md->w == w && md->moveOpacity != OPAQUE) + if (md->w == window && md->moveOpacity != OPAQUE) { /* modify opacity of windows that are not active */ sAttrib = *attrib; @@ -759,34 +821,32 @@ movePaintWindow (CompWindow *w, } } - UNWRAP (ms, s, paintWindow); - status = (*s->paintWindow) (w, attrib, transform, region, mask); - WRAP (ms, s, paintWindow, movePaintWindow); + status = window->paint (attrib, transform, region, mask); return status; } static CompOption * -moveGetDisplayOptions (CompPlugin *plugin, - CompDisplay *display, +moveGetDisplayOptions (CompObject *object, int *count) { - MOVE_DISPLAY (display); + CORE_DISPLAY (object); + MOVE_DISPLAY (d); *count = NUM_OPTIONS (md); return md->opt; } -static Bool -moveSetDisplayOption (CompPlugin *plugin, - CompDisplay *display, +static bool +moveSetDisplayOption (CompObject *object, const char *name, CompOptionValue *value) { CompOption *o; int index; - MOVE_DISPLAY (display); + CORE_DISPLAY (object); + MOVE_DISPLAY (d); o = compFindOption (md->opt, NUM_OPTIONS (md), name, &index); if (!o) @@ -801,7 +861,7 @@ moveSetDisplayOption (CompPlugin *plugin, } break; default: - return compSetDisplayOption (display, o, value); + return compSetDisplayOption (d, o, value); } return FALSE; @@ -816,19 +876,20 @@ static const CompMetadataOptionInfo moveDisplayOptionInfo[] = { { "lazy_positioning", "bool", 0, 0, 0 } }; -static Bool -moveInitDisplay (CompPlugin *p, - CompDisplay *d) +static bool +moveInitDisplay (CompObject *o) { MoveDisplay *md; int i; + CORE_DISPLAY (o); + if (!checkPluginABI ("core", CORE_ABIVERSION)) - return FALSE; + return false; - md = (MoveDisplay *) malloc (sizeof (MoveDisplay)); + md = new MoveDisplay (d); if (!md) - return FALSE; + return false; if (!compInitDisplayOptionsFromMetadata (d, &moveMetadata, @@ -836,16 +897,16 @@ moveInitDisplay (CompPlugin *p, md->opt, MOVE_DISPLAY_OPTION_NUM)) { - free (md); - return FALSE; + delete md; + return false; } md->screenPrivateIndex = allocateScreenPrivateIndex (d); if (md->screenPrivateIndex < 0) { compFiniDisplayOptions (d, md->opt, MOVE_DISPLAY_OPTION_NUM); - free (md); - return FALSE; + delete md; + return false; } md->moveOpacity = @@ -857,97 +918,124 @@ moveInitDisplay (CompPlugin *p, md->releaseButton = 0; for (i = 0; i < NUM_KEYS; i++) - md->key[i] = XKeysymToKeycode (d->display, + md->key[i] = XKeysymToKeycode (d->dpy (), XStringToKeysym (mKeys[i].name)); - WRAP (md, d, handleEvent, moveHandleEvent); - d->base.privates[displayPrivateIndex].ptr = md; + d->privates[displayPrivateIndex].ptr = md; - return TRUE; + return true; } static void -moveFiniDisplay (CompPlugin *p, - CompDisplay *d) +moveFiniDisplay (CompObject *o) { + CORE_DISPLAY (o); MOVE_DISPLAY (d); freeScreenPrivateIndex (d, md->screenPrivateIndex); - UNWRAP (md, d, handleEvent); - compFiniDisplayOptions (d, md->opt, MOVE_DISPLAY_OPTION_NUM); - free (md); + delete md; } -static Bool -moveInitScreen (CompPlugin *p, - CompScreen *s) +static bool +moveInitScreen (CompObject *o) { MoveScreen *ms; - MOVE_DISPLAY (s->display); + CORE_SCREEN (o); + MOVE_DISPLAY (s->display ()); - ms = (MoveScreen *) malloc (sizeof (MoveScreen)); + ms = new MoveScreen (s); if (!ms) - return FALSE; + return false; - ms->grabIndex = 0; + ms->windowPrivateIndex = allocateWindowPrivateIndex (s); + if (ms->windowPrivateIndex < 0) + { + delete ms; + return false; + } - ms->moveCursor = XCreateFontCursor (s->display->display, XC_fleur); + ms->grabIndex = 0; - WRAP (ms, s, paintWindow, movePaintWindow); + ms->moveCursor = XCreateFontCursor (s->display ()->dpy (), XC_fleur); - s->base.privates[md->screenPrivateIndex].ptr = ms; + s->privates[md->screenPrivateIndex].ptr = ms; - return TRUE; + return true; } static void -moveFiniScreen (CompPlugin *p, - CompScreen *s) +moveFiniScreen (CompObject *o) { + CORE_SCREEN (o); MOVE_SCREEN (s); - UNWRAP (ms, s, paintWindow); + freeWindowPrivateIndex (s, ms->windowPrivateIndex); if (ms->moveCursor) - XFreeCursor (s->display->display, ms->moveCursor); + XFreeCursor (s->display ()->dpy (), ms->moveCursor); - free (ms); + delete ms; } -static CompBool -moveInitObject (CompPlugin *p, - CompObject *o) +static bool +moveInitWindow (CompObject *o) +{ + MoveWindow *mw; + + CORE_WINDOW (o); + MOVE_SCREEN (w->screen ()); + + mw = new MoveWindow (w); + if (!mw) + return false; + + w->privates[ms->windowPrivateIndex].ptr = mw; + + return true; +} + +static void +moveFiniWindow (CompObject *o) +{ + CORE_WINDOW (o); + MOVE_WINDOW (w); + + delete mw; +} + +bool +MovePluginVTable::initObject (CompObject *o) { static InitPluginObjectProc dispTab[] = { (InitPluginObjectProc) 0, /* InitCore */ (InitPluginObjectProc) moveInitDisplay, - (InitPluginObjectProc) moveInitScreen + (InitPluginObjectProc) moveInitScreen, + (InitPluginObjectProc) moveInitWindow }; - RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o)); + RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (o)); } -static void -moveFiniObject (CompPlugin *p, - CompObject *o) +void +MovePluginVTable::finiObject (CompObject *o) { static FiniPluginObjectProc dispTab[] = { (FiniPluginObjectProc) 0, /* FiniCore */ (FiniPluginObjectProc) moveFiniDisplay, - (FiniPluginObjectProc) moveFiniScreen + (FiniPluginObjectProc) moveFiniScreen, + (FiniPluginObjectProc) moveFiniWindow }; - DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o)); + DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (o)); } -static CompOption * -moveGetObjectOptions (CompPlugin *plugin, - CompObject *object, +CompOption * +MovePluginVTable::getObjectOptions (CompObject *object, int *count) { static GetPluginObjectOptionsProc dispTab[] = { @@ -956,12 +1044,11 @@ moveGetObjectOptions (CompPlugin *plugin, }; RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab), - (CompOption *) (*count = 0), (plugin, object, count)); + (CompOption *) (*count = 0), (object, count)); } -static CompBool -moveSetObjectOption (CompPlugin *plugin, - CompObject *object, +bool +MovePluginVTable::setObjectOption (CompObject *object, const char *name, CompOptionValue *value) { @@ -971,57 +1058,48 @@ moveSetObjectOption (CompPlugin *plugin, }; RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab), FALSE, - (plugin, object, name, value)); + (object, name, value)); } -static Bool -moveInit (CompPlugin *p) +bool +MovePluginVTable::init () { if (!compInitPluginMetadataFromInfo (&moveMetadata, - p->vTable->name, + name (), moveDisplayOptionInfo, MOVE_DISPLAY_OPTION_NUM, 0, 0)) - return FALSE; + return false; displayPrivateIndex = allocateDisplayPrivateIndex (); if (displayPrivateIndex < 0) { compFiniMetadata (&moveMetadata); - return FALSE; + return false; } - compAddMetadataFromFile (&moveMetadata, p->vTable->name); + compAddMetadataFromFile (&moveMetadata, name ()); - return TRUE; + return true; } -static void -moveFini (CompPlugin *p) +void +MovePluginVTable::fini () { freeDisplayPrivateIndex (displayPrivateIndex); compFiniMetadata (&moveMetadata); } -static CompMetadata * -moveGetMetadata (CompPlugin *plugin) +CompMetadata * +MovePluginVTable::getMetadata () { return &moveMetadata; } -CompPluginVTable moveVTable = { - "move", - moveGetMetadata, - moveInit, - moveFini, - moveInitObject, - moveFiniObject, - moveGetObjectOptions, - moveSetObjectOption -}; +MovePluginVTable moveVTable; CompPluginVTable * -getCompPluginInfo20070830 (void) +getCompPluginInfo20080805 (void) { return &moveVTable; } diff --git a/src/Makefile.am b/src/Makefile.am index ee74639..a59866c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,11 +16,11 @@ compiz_SOURCES = \ privates.cpp \ object.cpp \ core.cpp \ - texture.cpp \ display.cpp \ screen.cpp \ window.cpp \ event.cpp \ + texture.cpp \ paint.cpp \ option.cpp \ plugin.cpp \ diff --git a/src/core.cpp b/src/core.cpp index 5e6f893..9e88618 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -24,10 +24,13 @@ */ #include <string.h> +#include <sys/poll.h> +#include <assert.h> #include <compiz-core.h> +#include "privatecore.h" -CompCore core; +CompCore *core; static char *corePrivateIndices = 0; static int corePrivateLen = 0; @@ -38,11 +41,11 @@ reallocCorePrivate (int size, { void *privates; - privates = realloc (core.base.privates, size * sizeof (CompPrivate)); + privates = realloc (core->privates, size * sizeof (CompPrivate)); if (!privates) return FALSE; - core.base.privates = (CompPrivate *) privates; + core->privates = (CompPrivate *) privates; return TRUE; } @@ -96,209 +99,545 @@ freeCorePrivateIndex (int index) compObjectFreePrivateIndex (NULL, COMP_OBJECT_TYPE_CORE, index); } -static CompBool -initCorePluginForObject (CompPlugin *p, - CompObject *o) + +#define TIMEVALDIFF(tv1, tv2) \ + ((tv1)->tv_sec == (tv2)->tv_sec || (tv1)->tv_usec >= (tv2)->tv_usec) ? \ + ((((tv1)->tv_sec - (tv2)->tv_sec) * 1000000) + \ + ((tv1)->tv_usec - (tv2)->tv_usec)) / 1000 : \ + ((((tv1)->tv_sec - 1 - (tv2)->tv_sec) * 1000000) + \ + (1000000 + (tv1)->tv_usec - (tv2)->tv_usec)) / 1000 + +CompCore::CompCore () { - return TRUE; + priv = new PrivateCore (this); + assert (priv); + + compObjectInit (this, 0, COMP_OBJECT_TYPE_CORE); } -static void -finiCorePluginForObject (CompPlugin *p, - CompObject *o) +bool +CompCore::init () { + WRAPABLE_INIT_HND(fileWatchAdded); + WRAPABLE_INIT_HND(fileWatchRemoved); + WRAPABLE_INIT_HND(initPluginForObject); + WRAPABLE_INIT_HND(finiPluginForObject); + WRAPABLE_INIT_HND(setOptionForPlugin); + WRAPABLE_INIT_HND(objectAdd); + WRAPABLE_INIT_HND(objectRemove); + WRAPABLE_INIT_HND(sessionEvent); + + CompPlugin *corePlugin = loadPlugin ("core"); + if (!corePlugin) + { + compLogMessage (0, "core", CompLogLevelFatal, + "Couldn't load core plugin"); + return false; + } + + if (!pushPlugin (corePlugin)) + { + compLogMessage (0, "core", CompLogLevelFatal, + "Couldn't activate core plugin"); + return false; + } + + return true; } -static CompBool -setOptionForPlugin (CompObject *object, - const char *plugin, - const char *name, - CompOptionValue *value) +CompCore::~CompCore () { CompPlugin *p; - p = findActivePlugin (plugin); - if (p && p->vTable->setObjectOption) - return (*p->vTable->setObjectOption) (p, object, name, value); + while (priv->displays) + removeDisplay (priv->displays); + + if (priv->watchPollFds) + free (priv->watchPollFds); + + while ((p = popPlugin ())) + unloadPlugin (p); - return FALSE; } -static void -coreObjectAdd (CompObject *parent, - CompObject *object) +CompDisplay * +CompCore::displays() { - object->parent = parent; + return priv->displays; } -static void -coreObjectRemove (CompObject *parent, - CompObject *object) +bool +CompCore::addDisplay (const char *name) { - object->parent = NULL; + + CompDisplay *prev; + CompDisplay *d = new CompDisplay(); + + if (!d) + return false; + + for (prev = priv->displays; prev && prev->next; prev = prev->next); + + if (prev) + prev->next = d; + else + priv->displays = d; + + if (!d->init (name)) + { + if (prev) + prev->next = NULL; + else + priv->displays = NULL; + delete d; + return false; + } + return true; } -static void -fileWatchAdded (CompCore *core, - CompFileWatch *fileWatch) +void +CompCore::removeDisplay (CompDisplay *d) { + CompDisplay *p; + + for (p = priv->displays; p; p = p->next) + if (p->next == d) + break; + + if (p) + p->next = d->next; + else + priv->displays = NULL; + + delete d; } -static void -fileWatchRemoved (CompCore *core, - CompFileWatch *fileWatch) +void +CompCore::eventLoop () { + struct timeval tv; + CompDisplay *d; + CompTimeout *t; + int time; + + for (d = priv->displays; d; d = d->next) + d->setWatchFdHandle (addWatchFd (ConnectionNumber (d->dpy()), + POLLIN, NULL, NULL)); + + for (;;) + { + if (restartSignal || shutDown) + break; + + for (d = priv->displays; d; d = d->next) + { + d->processEvents (); + } + + if (!priv->timeouts.empty()) + { + gettimeofday (&tv, 0); + priv->handleTimeouts (&tv); + + if ((*priv->timeouts.begin())->minLeft > 0) + { + std::list<CompTimeout *>::iterator it = priv->timeouts.begin(); + + t = (*it); + time = t->maxLeft; + while (it != priv->timeouts.end()) + { + t = (*it); + if (t->minLeft <= time) + break; + if (t->maxLeft < time) + time = t->maxLeft; + it++; + } + priv->doPoll (time); + } + } + else + { + priv->doPoll (-1); + } + } + + for (d = priv->displays; d; d = d->next) + removeWatchFd (d->getWatchFdHandle()); } -CompBool -initCore (void) -{ - CompPlugin *corePlugin; - compObjectInit (&core.base, 0, COMP_OBJECT_TYPE_CORE); - core.displays = NULL; +CompFileWatchHandle +CompCore::addFileWatch (const char *path, + int mask, + FileWatchCallBackProc callBack, + void *closure) +{ + CompFileWatch *fileWatch = new CompFileWatch(); + if (!fileWatch) + return 0; - core.tmpRegion = XCreateRegion (); - if (!core.tmpRegion) - return FALSE; + fileWatch->path = strdup (path); + fileWatch->mask = mask; + fileWatch->callBack = callBack; + fileWatch->closure = closure; + fileWatch->handle = priv->lastFileWatchHandle++; - core.outputRegion = XCreateRegion (); - if (!core.outputRegion) - { - XDestroyRegion (core.tmpRegion); - return FALSE; - } + if (priv->lastFileWatchHandle == MAXSHORT) + priv->lastFileWatchHandle = 1; - core.fileWatch = NULL; - core.lastFileWatchHandle = 1; + priv->fileWatch.push_front(fileWatch); - core.timeouts = NULL; - core.lastTimeoutHandle = 1; + fileWatchAdded (fileWatch); - core.watchFds = NULL; - core.lastWatchFdHandle = 1; - core.watchPollFds = NULL; - core.nWatchFds = 0; + return fileWatch->handle; +} - gettimeofday (&core.lastTimeout, 0); +void +CompCore::removeFileWatch (CompFileWatchHandle handle) +{ + std::list<CompFileWatch *>::iterator it; + CompFileWatch *w; - core.initPluginForObject = initCorePluginForObject; - core.finiPluginForObject = finiCorePluginForObject; + for (it = priv->fileWatch.begin(); it != priv->fileWatch.end(); it++) + if ((*it)->handle == handle) + break; - core.setOptionForPlugin = setOptionForPlugin; + if (it == priv->fileWatch.end()) + return; - core.objectAdd = coreObjectAdd; - core.objectRemove = coreObjectRemove; + w = (*it); + priv->fileWatch.erase (it); - core.fileWatchAdded = fileWatchAdded; - core.fileWatchRemoved = fileWatchRemoved; + fileWatchRemoved (w); - core.sessionEvent = sessionEvent; + delete w; +} - corePlugin = loadPlugin ("core"); - if (!corePlugin) - { - compLogMessage (0, "core", CompLogLevelFatal, - "Couldn't load core plugin"); - return FALSE; - } +void +PrivateCore::addTimeout (CompTimeout *timeout) +{ + std::list<CompTimeout *>::iterator it; - if (!pushPlugin (corePlugin)) + for (it = timeouts.begin(); it != timeouts.end(); it++) { - compLogMessage (0, "core", CompLogLevelFatal, - "Couldn't activate core plugin"); - return FALSE; + if (timeout->minTime < (*it)->minLeft) + break; } - return TRUE; + timeout->minLeft = timeout->minTime; + timeout->maxLeft = timeout->maxTime; + + timeouts.insert (it, timeout); } -void -finiCore (void) +CompTimeoutHandle +CompCore::addTimeout (int minTime, + int maxTime, + CallBackProc callBack, + void *closure) { - CompPlugin *p; + CompTimeout *timeout = new CompTimeout(); - while (core.displays) - removeDisplay (core.displays); + if (!timeout) + return 0; - if (core.watchPollFds) - free (core.watchPollFds); + timeout->minTime = minTime; + timeout->maxTime = (maxTime >= minTime) ? maxTime : minTime; + timeout->callBack = callBack; + timeout->closure = closure; + timeout->handle = priv->lastTimeoutHandle++; - while ((p = popPlugin ())) - unloadPlugin (p); + if (priv->lastTimeoutHandle == MAXSHORT) + priv->lastTimeoutHandle = 1; + + priv->addTimeout (timeout); - XDestroyRegion (core.outputRegion); - XDestroyRegion (core.tmpRegion); + return timeout->handle; } -void -addDisplayToCore (CompDisplay *d) +void * +CompCore::removeTimeout (CompTimeoutHandle handle) { - CompDisplay *prev; + std::list<CompTimeout *>::iterator it; + CompTimeout *t; + void *closure = NULL; - for (prev = core.displays; prev && prev->next; prev = prev->next); + for (it = priv->timeouts.begin(); it != priv->timeouts.end(); it++) + if ((*it)->handle == handle) + break; - if (prev) - prev->next = d; - else - core.displays = d; + if (it == priv->timeouts.end()) + return NULL; + + t = (*it); + priv->timeouts.erase (it); + + closure = t->closure; + + delete t; + + return closure; } -CompFileWatchHandle -addFileWatch (const char *path, - int mask, - FileWatchCallBackProc callBack, - void *closure) +CompWatchFdHandle +CompCore::addWatchFd (int fd, + short int events, + CallBackProc callBack, + void *closure) { - CompFileWatch *fileWatch; + CompWatchFd *watchFd = new CompWatchFd(); - fileWatch = (CompFileWatch *) malloc (sizeof (CompFileWatch)); - if (!fileWatch) + if (!watchFd) return 0; - fileWatch->path = strdup (path); - fileWatch->mask = mask; - fileWatch->callBack = callBack; - fileWatch->closure = closure; - fileWatch->handle = core.lastFileWatchHandle++; + watchFd->fd = fd; + watchFd->callBack = callBack; + watchFd->closure = closure; + watchFd->handle = priv->lastWatchFdHandle++; - if (core.lastFileWatchHandle == MAXSHORT) - core.lastFileWatchHandle = 1; + if (priv->lastWatchFdHandle == MAXSHORT) + priv->lastWatchFdHandle = 1; - fileWatch->next = core.fileWatch; - core.fileWatch = fileWatch; + priv->watchFds.push_front (watchFd); - (*core.fileWatchAdded) (&core, fileWatch); + priv->nWatchFds++; - return fileWatch->handle; + priv->watchPollFds = (struct pollfd *) realloc (priv->watchPollFds, + priv->nWatchFds * sizeof (struct pollfd)); + + priv->watchPollFds[priv->nWatchFds - 1].fd = fd; + priv->watchPollFds[priv->nWatchFds - 1].events = events; + + return watchFd->handle; } void -removeFileWatch (CompFileWatchHandle handle) +CompCore::removeWatchFd (CompWatchFdHandle handle) { - CompFileWatch *p = 0, *w; + std::list<CompWatchFd *>::iterator it; + CompWatchFd *w; + int i; - for (w = core.fileWatch; w; w = w->next) - { - if (w->handle == handle) + for (it = priv->watchFds.begin(), i = priv->nWatchFds - 1; + it != priv->watchFds.end(); it++, i--) + if ((*it)->handle == handle) break; - p = w; + if (it == priv->watchFds.end()) + return; + + w = (*it); + priv->watchFds.erase (it); + + priv->nWatchFds--; + + if (i < priv->nWatchFds) + memmove (&priv->watchPollFds[i], &priv->watchPollFds[i + 1], + (priv->nWatchFds - i) * sizeof (struct pollfd)); + + delete w; +} + +short int +PrivateCore::watchFdEvents (CompWatchFdHandle handle) +{ + std::list<CompWatchFd *>::iterator it; + int i; + + for (it = watchFds.begin(), i = nWatchFds - 1; it != watchFds.end(); + it++, i--) + if ((*it)->handle == handle) + return watchPollFds[i].revents; + + return 0; +} + +int +PrivateCore::doPoll (int timeout) +{ + int rv; + + rv = poll (watchPollFds, nWatchFds, timeout); + if (rv) + { + std::list<CompWatchFd *>::iterator it; + int i; + + for (it = watchFds.begin(), i = nWatchFds - 1; it != watchFds.end(); + it++, i--) + if (watchPollFds[i].revents != 0 && (*it)->callBack) + (*(*it)->callBack) ((*it)->closure); } - if (w) + return rv; +} + +void +PrivateCore::handleTimeouts (struct timeval *tv) +{ + CompTimeout *t; + int timeDiff; + std::list<CompTimeout *>::iterator it; + + timeDiff = TIMEVALDIFF (tv, &lastTimeout); + + /* handle clock rollback */ + if (timeDiff < 0) + timeDiff = 0; + + for (it = timeouts.begin(); it != timeouts.end(); it++) { - if (p) - p->next = w->next; + t = (*it); + t->minLeft -= timeDiff; + t->maxLeft -= timeDiff; + } + + while (timeouts.begin() != timeouts.end() && + (*timeouts.begin())->minLeft <= 0) + { + t = (*timeouts.begin()); + timeouts.pop_front(); + + if ((*t->callBack) (t->closure)) + { + addTimeout (t); + } else - core.fileWatch = w->next; + { + delete t; + } + } - (*core.fileWatchRemoved) (&core, w); + lastTimeout = *tv; +} - if (w->path) - free (w->path); - free (w); - } +void +CompCore::fileWatchAdded (CompFileWatch *watch) + WRAPABLE_HND_FUNC(fileWatchAdded, watch) + +void +CompCore::fileWatchRemoved (CompFileWatch *watch) + WRAPABLE_HND_FUNC(fileWatchRemoved, watch) + +bool +CompCore::initPluginForObject (CompPlugin *plugin, CompObject *object) +{ + WRAPABLE_HND_FUNC_RETURN(bool, initPluginForObject, plugin, object) + return true; +} + +void +CompCore::finiPluginForObject (CompPlugin *plugin, CompObject *object) + WRAPABLE_HND_FUNC(finiPluginForObject, plugin, object) + + +bool +CompCore::setOptionForPlugin (CompObject *object, + const char *plugin, + const char *name, + CompOptionValue *value) +{ + WRAPABLE_HND_FUNC_RETURN(bool, setOptionForPlugin, + object, plugin, name, value) + + CompPlugin *p = findActivePlugin (plugin); + if (p) + return p->vTable->setObjectOption (object, name, value); + + return false; +} + +void +CompCore::objectAdd (CompObject *parent, CompObject *object) +{ + WRAPABLE_HND_FUNC(objectAdd, parent, object) + object->parent = parent; +} + +void +CompCore::objectRemove (CompObject *parent, CompObject *object) +{ + WRAPABLE_HND_FUNC(objectRemove, parent, object) + object->parent = NULL; +} + +void +CompCore::sessionEvent (CompSessionEvent event, + CompOption *arguments, + unsigned int nArguments) + WRAPABLE_HND_FUNC(sessionEvent, event, arguments, nArguments) + +CoreInterface::CoreInterface () +{ + WRAPABLE_INIT_FUNC(fileWatchAdded); + WRAPABLE_INIT_FUNC(fileWatchRemoved); + WRAPABLE_INIT_FUNC(initPluginForObject); + WRAPABLE_INIT_FUNC(finiPluginForObject); + WRAPABLE_INIT_FUNC(setOptionForPlugin); + WRAPABLE_INIT_FUNC(objectAdd); + WRAPABLE_INIT_FUNC(objectRemove); + WRAPABLE_INIT_FUNC(sessionEvent); +} + +void +CoreInterface::fileWatchAdded (CompFileWatch *watch) + WRAPABLE_DEF_FUNC(fileWatchAdded, watch) + +void +CoreInterface::fileWatchRemoved (CompFileWatch *watch) + WRAPABLE_DEF_FUNC(fileWatchRemoved, watch) + +bool +CoreInterface::initPluginForObject (CompPlugin *plugin, CompObject *object) + WRAPABLE_DEF_FUNC_RETURN(initPluginForObject, plugin, object) + +void +CoreInterface::finiPluginForObject (CompPlugin *plugin, CompObject *object) + WRAPABLE_DEF_FUNC(finiPluginForObject, plugin, object) + + +bool +CoreInterface::setOptionForPlugin (CompObject *object, + const char *plugin, + const char *name, + CompOptionValue *value) + WRAPABLE_DEF_FUNC_RETURN(setOptionForPlugin, + object, plugin, name, value) + +void +CoreInterface::objectAdd (CompObject *parent, CompObject *object) + WRAPABLE_DEF_FUNC(objectAdd, parent, object) + +void +CoreInterface::objectRemove (CompObject *parent, CompObject *object) + WRAPABLE_DEF_FUNC(objectRemove, parent, object) + +void +CoreInterface::sessionEvent (CompSessionEvent event, + CompOption *arguments, + unsigned int nArguments) + WRAPABLE_DEF_FUNC(sessionEvent, event, arguments, nArguments) + + +PrivateCore::PrivateCore (CompCore *core) : + core (core), + displays (0), + fileWatch (0), + lastFileWatchHandle (1), + timeouts (0), + lastTimeoutHandle (1), + watchFds (0), + lastWatchFdHandle (1), + watchPollFds (0), + nWatchFds (0) +{ + gettimeofday (&lastTimeout, 0); +} + +PrivateCore::~PrivateCore () +{ } diff --git a/src/cursor.cpp b/src/cursor.cpp index baca1c3..a2f398b 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -26,6 +26,7 @@ #include <stdlib.h> #include <compiz-core.h> +#include "privatescreen.h" static void setCursorMatrix (CompCursor *c) @@ -36,20 +37,20 @@ setCursorMatrix (CompCursor *c) } void -addCursor (CompScreen *s) +CompScreen::addCursor () { CompCursor *c; c = (CompCursor *) malloc (sizeof (CompCursor)); if (c) { - c->screen = s; + c->screen = this; c->image = NULL; c->x = 0; c->y = 0; - c->next = s->cursors; - s->cursors = c; + c->next = priv->cursors; + priv->cursors = c; updateCursor (c, 0, 0, 0); @@ -57,12 +58,13 @@ addCursor (CompScreen *s) } } -Bool -damageCursorRect (CompCursor *c, - Bool initial, - BoxPtr rect) +bool +CompScreen::damageCursorRect (CompCursor *c, + bool initial, + BoxPtr rect) { - return FALSE; + WRAPABLE_HND_FUNC_RETURN(bool, damageCursorRect, c, initial, rect) + return false; } void @@ -71,12 +73,12 @@ addCursorDamageRect (CompCursor *c, { REGION region; - if (c->screen->damageMask & COMP_SCREEN_DAMAGE_ALL_MASK) + if (c->screen->damageMask () & COMP_SCREEN_DAMAGE_ALL_MASK) return; region.extents = *rect; - if (!(*c->screen->damageCursorRect) (c, FALSE, ®ion.extents)) + if (!c->screen->damageCursorRect (c, false, ®ion.extents)) { region.extents.x1 += c->x; region.extents.y1 += c->y; @@ -86,7 +88,7 @@ addCursorDamageRect (CompCursor *c, region.rects = ®ion.extents; region.numRects = region.size = 1; - damageScreenRegion (c->screen, ®ion); + c->screen->damageRegion (®ion); } } @@ -95,7 +97,7 @@ addCursorDamage (CompCursor *c) { BoxRec box; - if (c->screen->damageMask & COMP_SCREEN_DAMAGE_ALL_MASK) + if (c->screen->damageMask () & COMP_SCREEN_DAMAGE_ALL_MASK) return; box.x1 = 0; @@ -117,10 +119,10 @@ updateCursor (CompCursor *c, { CompCursorImage *cursorImage; - cursorImage = findCursorImageAtScreen (c->screen, serial); + cursorImage = c->screen->findCursorImage (serial); if (!cursorImage) { - Display *dpy = c->screen->display->display; + Display *dpy = c->screen->display ()->dpy (); XFixesCursorImage *image; image = XFixesGetCursorImage (dpy); @@ -158,8 +160,8 @@ updateCursor (CompCursor *c, XFree (image); - cursorImage->next = c->screen->cursorImages; - c->screen->cursorImages = cursorImage; + cursorImage->next = c->screen->cursorImages (); + c->screen->cursorImages () = cursorImage; } if (c->image) diff --git a/src/display.cpp b/src/display.cpp index 09223fb..0efe8d5 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -38,37 +38,43 @@ #include <X11/Xlib.h> #include <X11/Xatom.h> +#include <X11/Xproto.h> #include <X11/extensions/Xcomposite.h> #include <X11/extensions/Xrandr.h> #include <X11/extensions/shape.h> #include <compiz-core.h> +#include "privatedisplay.h" +#include "privatescreen.h" +#include "privatewindow.h" static unsigned int virtualModMask[] = { CompAltMask, CompMetaMask, CompSuperMask, CompHyperMask, CompModeSwitchMask, CompNumLockMask, CompScrollLockMask }; -static CompScreen *targetScreen = NULL; -static CompOutput *targetOutput; +CompScreen *targetScreen = NULL; +CompOutput *targetOutput; -static Bool inHandleEvent = FALSE; +Bool inHandleEvent = FALSE; -static const CompTransform identity = { - { - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0 - } -}; int lastPointerX = 0; int lastPointerY = 0; int pointerX = 0; int pointerY = 0; -#define NUM_OPTIONS(d) (sizeof ((d)->opt) / sizeof (CompOption)) +#define MwmHintsFunctions (1L << 0) +#define MwmHintsDecorations (1L << 1) +#define PropMotifWmHintElements 3 + +typedef struct { + unsigned long flags; + unsigned long functions; + unsigned long decorations; +} MwmHints; + +#define NUM_OPTIONS(d) (sizeof ((d)->priv->opt) / sizeof (CompOption)) static char *displayPrivateIndices = 0; static int displayPrivateLen = 0; @@ -80,13 +86,13 @@ reallocDisplayPrivate (int size, CompDisplay *d; void *privates; - for (d = core.displays; d; d = d->next) + for (d = core->displays(); d; d = d->next) { - privates = realloc (d->base.privates, size * sizeof (CompPrivate)); + privates = realloc (d->privates, size * sizeof (CompPrivate)); if (!privates) return FALSE; - d->base.privates = (CompPrivate *) privates; + d->privates = (CompPrivate *) privates; } return TRUE; @@ -117,9 +123,9 @@ forEachDisplayObject (CompObject *parent, { CompDisplay *d; - for (d = core.displays; d; d = d->next) + for (d = core->displays(); d; d = d->next) { - if (!(*proc) (&d->base, closure)) + if (!(*proc) (d, closure)) return FALSE; } } @@ -140,7 +146,7 @@ findDisplayObject (CompObject *parent, if (parent->type == COMP_OBJECT_TYPE_CORE) { if (!name || !name[0]) - return &core.displays->base; + return core->displays (); } return NULL; @@ -158,12 +164,12 @@ freeDisplayPrivateIndex (int index) compObjectFreePrivateIndex (NULL, COMP_OBJECT_TYPE_DISPLAY, index); } -static Bool -closeWin (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::closeWin (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; @@ -172,19 +178,19 @@ closeWin (CompDisplay *d, xid = getIntOptionNamed (option, nOption, "window", 0); time = getIntOptionNamed (option, nOption, "time", CurrentTime); - w = findTopLevelWindowAtDisplay (d, xid); - if (w && (w->actions & CompWindowActionCloseMask)) - closeWindow (w, time); + w = d->findTopLevelWindow (xid); + if (w && (w->priv->actions & CompWindowActionCloseMask)) + w->close (time); - return TRUE; + return true; } -static Bool -mainMenu (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompScreen::mainMenu (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompScreen *s; Window xid; @@ -193,20 +199,20 @@ mainMenu (CompDisplay *d, xid = getIntOptionNamed (option, nOption, "root", 0); time = getIntOptionNamed (option, nOption, "time", CurrentTime); - s = findScreenAtDisplay (d, xid); - if (s && !s->maxGrab) - toolkitAction (s, s->display->toolkitActionMainMenuAtom, time, s->root, - 0, 0, 0); + s = d->findScreen (xid); + if (s && !s->priv->maxGrab) + s->toolkitAction (s->display ()->atoms().toolkitActionMainMenu, time, + s->priv->root, 0, 0, 0); - return TRUE; + return true; } -static Bool -runDialog (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompScreen::runDialog (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompScreen *s; Window xid; @@ -215,274 +221,203 @@ runDialog (CompDisplay *d, xid = getIntOptionNamed (option, nOption, "root", 0); time = getIntOptionNamed (option, nOption, "time", CurrentTime); - s = findScreenAtDisplay (d, xid); - if (s && !s->maxGrab) - toolkitAction (s, s->display->toolkitActionRunDialogAtom, time, s->root, - 0, 0, 0); + s = d->findScreen (xid); + if (s && !s->priv->maxGrab) + s->toolkitAction (s->display ()->atoms().toolkitActionRunDialog, time, + s->priv->root , 0, 0, 0); - return TRUE; + return true; } -static Bool -unmaximize (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::unmaximize (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); + w = d->findTopLevelWindow (xid); if (w) - maximizeWindow (w, 0); + w->maximize (0); - return TRUE; + return true; } -static Bool -minimize (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::minimize (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); - if (w && (w->actions & CompWindowActionMinimizeMask)) - minimizeWindow (w); + w = d->findTopLevelWindow (xid); + if (w && (w->actions () & CompWindowActionMinimizeMask)) + w->minimize (); - return TRUE; + return true; } -static Bool -maximize (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::maximize (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); + w = d->findTopLevelWindow (xid); if (w) - maximizeWindow (w, MAXIMIZE_STATE); + w->maximize (MAXIMIZE_STATE); - return TRUE; + return true; } -static Bool -maximizeHorizontally (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::maximizeHorizontally (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); + w = d->findTopLevelWindow (xid); if (w) - maximizeWindow (w, w->state | CompWindowStateMaximizedHorzMask); + w->maximize (w->state () | CompWindowStateMaximizedHorzMask); - return TRUE; + return true; } -static Bool -maximizeVertically (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::maximizeVertically (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); + w = d->findTopLevelWindow (xid); if (w) - maximizeWindow (w, w->state | CompWindowStateMaximizedVertMask); + w->maximize (w->state () | CompWindowStateMaximizedVertMask); - return TRUE; + return true; } -static Bool -showDesktop (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompScreen::showDesktop (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompScreen *s; Window xid; xid = getIntOptionNamed (option, nOption, "root", 0); - s = findScreenAtDisplay (d, xid); + s = d->findScreen (xid); if (s) { - if (s->showingDesktopMask == 0) - (*s->enterShowDesktopMode) (s); + if (s->priv->showingDesktopMask == 0) + s->enterShowDesktopMode (); else - (*s->leaveShowDesktopMode) (s, NULL); + s->leaveShowDesktopMode (NULL); } - return TRUE; + return true; } -static Bool -toggleSlowAnimations (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompScreen::toggleSlowAnimations (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompScreen *s; Window xid; xid = getIntOptionNamed (option, nOption, "root", 0); - s = findScreenAtDisplay (d, xid); + s = d->findScreen (xid); if (s) - s->slowAnimations = !s->slowAnimations; - - return TRUE; -} - -static Bool -raiseInitiate (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) -{ - CompWindow *w; - Window xid; - - xid = getIntOptionNamed (option, nOption, "window", 0); - - w = findTopLevelWindowAtDisplay (d, xid); - if (w) - raiseWindow (w); - - return TRUE; -} - -static Bool -lowerInitiate (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) -{ - CompWindow *w; - Window xid; - - xid = getIntOptionNamed (option, nOption, "window", 0); - - w = findTopLevelWindowAtDisplay (d, xid); - if (w) - lowerWindow (w); - - return TRUE; -} - -static void -changeWindowOpacity (CompWindow *w, - int direction) -{ - CompScreen *s = w->screen; - int step, opacity; - - if (w->attrib.override_redirect) - return; - - if (w->type & CompWindowTypeDesktopMask) - return; - - step = (0xff * s->opt[COMP_SCREEN_OPTION_OPACITY_STEP].value.i) / 100; - - w->opacityFactor = w->opacityFactor + step * direction; - if (w->opacityFactor > 0xff) - { - w->opacityFactor = 0xff; - } - else if (w->opacityFactor < step) - { - w->opacityFactor = step; - } + s->priv->slowAnimations = !s->priv->slowAnimations; - opacity = (w->opacity * w->opacityFactor) / 0xff; - if (opacity != w->paint.opacity) - { - w->paint.opacity = opacity; - addWindowDamage (w); - } + return true; } -static Bool -increaseOpacity (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::raiseInitiate (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); + w = d->findTopLevelWindow (xid); if (w) - changeWindowOpacity (w, 1); + w->raise (); - return TRUE; + return true; } -static Bool -decreaseOpacity (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::lowerInitiate (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); + w = d->findTopLevelWindow (xid); if (w) - changeWindowOpacity (w, -1); + w->lower (); - return TRUE; + return true; } -static Bool -runCommandDispatch (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompDisplay::runCommandDispatch (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompScreen *s; Window xid; xid = getIntOptionNamed (option, nOption, "root", 0); - s = findScreenAtDisplay (d, xid); + s = d->findScreen (xid); if (s) { int index = -1; @@ -490,7 +425,7 @@ runCommandDispatch (CompDisplay *d, while (i <= COMP_DISPLAY_OPTION_RUN_COMMAND11_KEY) { - if (action == &d->opt[i].value.action) + if (action == &d->priv->opt[i].value.action) { index = i - COMP_DISPLAY_OPTION_RUN_COMMAND0_KEY + COMP_DISPLAY_OPTION_COMMAND0; @@ -501,186 +436,183 @@ runCommandDispatch (CompDisplay *d, } if (index > 0) - runCommand (s, d->opt[index].value.s); + s->runCommand (d->priv->opt[index].value.s); } - return TRUE; + return true; } -static Bool -runCommandScreenshot (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompDisplay::runCommandScreenshot (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompScreen *s; Window xid; xid = getIntOptionNamed (option, nOption, "root", 0); - s = findScreenAtDisplay (d, xid); + s = d->findScreen (xid); if (s) - runCommand (s, d->opt[COMP_DISPLAY_OPTION_SCREENSHOT].value.s); + s->runCommand (d->priv->opt[COMP_DISPLAY_OPTION_SCREENSHOT].value.s); - return TRUE; + return true; } -static Bool -runCommandWindowScreenshot (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompDisplay::runCommandWindowScreenshot (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompScreen *s; Window xid; xid = getIntOptionNamed (option, nOption, "root", 0); - s = findScreenAtDisplay (d, xid); + s = d->findScreen (xid); if (s) - runCommand (s, d->opt[COMP_DISPLAY_OPTION_WINDOW_SCREENSHOT].value.s); + s->runCommand ( + d->priv->opt[COMP_DISPLAY_OPTION_WINDOW_SCREENSHOT].value.s); - return TRUE; + return true; } -static Bool -runCommandTerminal (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompDisplay::runCommandTerminal (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompScreen *s; Window xid; xid = getIntOptionNamed (option, nOption, "root", 0); - s = findScreenAtDisplay (d, xid); + s = d->findScreen (xid); if (s) - runCommand (s, d->opt[COMP_DISPLAY_OPTION_TERMINAL].value.s); + s->runCommand (d->priv->opt[COMP_DISPLAY_OPTION_TERMINAL].value.s); - return TRUE; + return true; } -static Bool -windowMenu (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompScreen::windowMenu (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); - if (w && !w->screen->maxGrab) + w = d->findTopLevelWindow (xid); + if (w && !w->screen ()->priv->maxGrab) { int x, y, button; Time time; time = getIntOptionNamed (option, nOption, "time", CurrentTime); button = getIntOptionNamed (option, nOption, "button", 0); - x = getIntOptionNamed (option, nOption, "x", w->attrib.x); - y = getIntOptionNamed (option, nOption, "y", w->attrib.y); - - toolkitAction (w->screen, - w->screen->display->toolkitActionWindowMenuAtom, - time, - w->id, - button, - x, - y); + x = getIntOptionNamed (option, nOption, "x", w->attrib ().x); + y = getIntOptionNamed (option, nOption, "y", w->attrib ().y); + + w->screen ()->toolkitAction ( + w->screen ()->display ()->atoms().toolkitActionWindowMenu, + time, w->id (), button, x, y); } - return TRUE; + return true; } -static Bool -toggleMaximized (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::toggleMaximized (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); + w = d->findTopLevelWindow (xid); if (w) { - if ((w->state & MAXIMIZE_STATE) == MAXIMIZE_STATE) - maximizeWindow (w, 0); + if ((w->priv->state & MAXIMIZE_STATE) == MAXIMIZE_STATE) + w->maximize (0); else - maximizeWindow (w, MAXIMIZE_STATE); + w->maximize (MAXIMIZE_STATE); } - return TRUE; + return true; } -static Bool -toggleMaximizedHorizontally (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::toggleMaximizedHorizontally (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); + w = d->findTopLevelWindow (xid); if (w) - maximizeWindow (w, w->state ^ CompWindowStateMaximizedHorzMask); + w->maximize (w->priv->state ^ CompWindowStateMaximizedHorzMask); - return TRUE; + return true; } -static Bool -toggleMaximizedVertically (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::toggleMaximizedVertically (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); + w = d->findTopLevelWindow (xid); if (w) - maximizeWindow (w, w->state ^ CompWindowStateMaximizedVertMask); + w->maximize (w->priv->state ^ CompWindowStateMaximizedVertMask); - return TRUE; + return true; } -static Bool -shade (CompDisplay *d, - CompAction *action, - CompActionState state, - CompOption *option, - int nOption) +bool +CompWindow::shade (CompDisplay *d, + CompAction *action, + CompActionState state, + CompOption *option, + int nOption) { CompWindow *w; Window xid; xid = getIntOptionNamed (option, nOption, "window", 0); - w = findTopLevelWindowAtDisplay (d, xid); - if (w && (w->actions & CompWindowActionShadeMask)) + w = d->findTopLevelWindow (xid); + if (w && (w->priv->actions & CompWindowActionShadeMask)) { - w->state ^= CompWindowStateShadedMask; - updateWindowAttributes (w, CompStackingUpdateModeNone); + w->priv->state ^= CompWindowStateShadedMask; + w->updateAttributes (CompStackingUpdateModeNone); } - return TRUE; + return true; } const CompMetadataOptionInfo coreDisplayOptionInfo[COMP_DISPLAY_OPTION_NUM] = { @@ -690,10 +622,10 @@ const CompMetadataOptionInfo coreDisplayOptionInfo[COMP_DISPLAY_OPTION_NUM] = { { "click_to_focus", "bool", 0, 0, 0 }, { "autoraise", "bool", 0, 0, 0 }, { "autoraise_delay", "int", 0, 0, 0 }, - { "close_window_key", "key", 0, closeWin, 0 }, - { "close_window_button", "button", 0, closeWin, 0 }, - { "main_menu_key", "key", 0, mainMenu, 0 }, - { "run_key", "key", 0, runDialog, 0 }, + { "close_window_key", "key", 0, CompWindow::closeWin, 0 }, + { "close_window_button", "button", 0, CompWindow::closeWin, 0 }, + { "main_menu_key", "key", 0, CompScreen::mainMenu, 0 }, + { "run_key", "key", 0, CompScreen::runDialog, 0 }, { "command0", "string", 0, 0, 0 }, { "command1", "string", 0, 0, 0 }, { "command2", "string", 0, 0, 0 }, @@ -706,564 +638,795 @@ const CompMetadataOptionInfo coreDisplayOptionInfo[COMP_DISPLAY_OPTION_NUM] = { { "command9", "string", 0, 0, 0 }, { "command10", "string", 0, 0, 0 }, { "command11", "string", 0, 0, 0 }, - { "run_command0_key", "key", 0, runCommandDispatch, 0 }, - { "run_command1_key", "key", 0, runCommandDispatch, 0 }, - { "run_command2_key", "key", 0, runCommandDispatch, 0 }, - { "run_command3_key", "key", 0, runCommandDispatch, 0 }, - { "run_command4_key", "key", 0, runCommandDispatch, 0 }, - { "run_command5_key", "key", 0, runCommandDispatch, 0 }, - { "run_command6_key", "key", 0, runCommandDispatch, 0 }, - { "run_command7_key", "key", 0, runCommandDispatch, 0 }, - { "run_command8_key", "key", 0, runCommandDispatch, 0 }, - { "run_command9_key", "key", 0, runCommandDispatch, 0 }, - { "run_command10_key", "key", 0, runCommandDispatch, 0 }, - { "run_command11_key", "key", 0, runCommandDispatch, 0 }, - { "slow_animations_key", "key", 0, toggleSlowAnimations, 0 }, - { "raise_window_key", "key", 0, raiseInitiate, 0 }, - { "raise_window_button", "button", 0, raiseInitiate, 0 }, - { "lower_window_key", "key", 0, lowerInitiate, 0 }, - { "lower_window_button", "button", 0, lowerInitiate, 0 }, - { "unmaximize_window_key", "key", 0, unmaximize, 0 }, - { "minimize_window_key", "key", 0, minimize, 0 }, - { "minimize_window_button", "button", 0, minimize, 0 }, - { "maximize_window_key", "key", 0, maximize, 0 }, - { "maximize_window_horizontally_key", "key", 0, maximizeHorizontally, 0 }, - { "maximize_window_vertically_key", "key", 0, maximizeVertically, 0 }, - { "opacity_increase_button", "button", 0, increaseOpacity, 0 }, - { "opacity_decrease_button", "button", 0, decreaseOpacity, 0 }, + { "run_command0_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command1_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command2_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command3_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command4_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command5_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command6_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command7_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command8_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command9_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command10_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "run_command11_key", "key", 0, CompDisplay::runCommandDispatch, 0 }, + { "slow_animations_key", "key", 0, CompScreen::toggleSlowAnimations, 0 }, + { "raise_window_key", "key", 0, CompWindow::raiseInitiate, 0 }, + { "raise_window_button", "button", 0, CompWindow::raiseInitiate, 0 }, + { "lower_window_key", "key", 0, CompWindow::lowerInitiate, 0 }, + { "lower_window_button", "button", 0, CompWindow::lowerInitiate, 0 }, + { "unmaximize_window_key", "key", 0, CompWindow::unmaximize, 0 }, + { "minimize_window_key", "key", 0, CompWindow::minimize, 0 }, + { "minimize_window_button", "button", 0, CompWindow::minimize, 0 }, + { "maximize_window_key", "key", 0, CompWindow::maximize, 0 }, + { "maximize_window_horizontally_key", "key", 0, + CompWindow::maximizeHorizontally, 0 }, + { "maximize_window_vertically_key", "key", 0, + CompWindow::maximizeVertically, 0 }, { "command_screenshot", "string", 0, 0, 0 }, - { "run_command_screenshot_key", "key", 0, runCommandScreenshot, 0 }, + { "run_command_screenshot_key", "key", 0, + CompDisplay::runCommandScreenshot, 0 }, { "command_window_screenshot", "string", 0, 0, 0 }, { "run_command_window_screenshot_key", "key", 0, - runCommandWindowScreenshot, 0 }, - { "window_menu_button", "button", 0, windowMenu, 0 }, - { "window_menu_key", "key", 0, windowMenu, 0 }, - { "show_desktop_key", "key", 0, showDesktop, 0 }, - { "show_desktop_edge", "edge", 0, showDesktop, 0 }, + CompDisplay::runCommandWindowScreenshot, 0 }, + { "window_menu_button", "button", 0, CompScreen::windowMenu, 0 }, + { "window_menu_key", "key", 0, CompScreen::windowMenu, 0 }, + { "show_desktop_key", "key", 0, CompScreen::showDesktop, 0 }, + { "show_desktop_edge", "edge", 0, CompScreen::showDesktop, 0 }, { "raise_on_click", "bool", 0, 0, 0 }, { "audible_bell", "bool", 0, 0, 0 }, - { "toggle_window_maximized_key", "key", 0, toggleMaximized, 0 }, - { "toggle_window_maximized_button", "button", 0, toggleMaximized, 0 }, + { "toggle_window_maximized_key", "key", 0, + CompWindow::toggleMaximized, 0 }, + { "toggle_window_maximized_button", "button", 0, + CompWindow::toggleMaximized, 0 }, { "toggle_window_maximized_horizontally_key", "key", 0, - toggleMaximizedHorizontally, 0 }, + CompWindow::toggleMaximizedHorizontally, 0 }, { "toggle_window_maximized_vertically_key", "key", 0, - toggleMaximizedVertically, 0 }, + CompWindow::toggleMaximizedVertically, 0 }, { "hide_skip_taskbar_windows", "bool", 0, 0, 0 }, - { "toggle_window_shaded_key", "key", 0, shade, 0 }, + { "toggle_window_shaded_key", "key", 0, CompWindow::shade, 0 }, { "ignore_hints_when_maximized", "bool", 0, 0, 0 }, { "command_terminal", "string", 0, 0, 0 }, - { "run_command_terminal_key", "key", 0, runCommandTerminal, 0 }, + { "run_command_terminal_key", "key", 0, + CompDisplay::runCommandTerminal, 0 }, { "ping_delay", "int", "<min>1000</min>", 0, 0 }, { "edge_delay", "int", "<min>0</min>", 0, 0 } }; CompOption * -getDisplayOptions (CompPlugin *plugin, - CompDisplay *display, - int *count) +CompDisplay::getDisplayOptions (CompObject *object, + int *count) { + CompDisplay *display = (CompDisplay *) object; *count = NUM_OPTIONS (display); - return display->opt; + return display->priv->opt; } -static void -setAudibleBell (CompDisplay *display, - Bool audible) +bool +CompDisplay::pingTimeout (void *closure) { - if (display->xkbExtension) - XkbChangeEnabledControls (display->display, - XkbUseCoreKbd, - XkbAudibleBellMask, - audible ? XkbAudibleBellMask : 0); + CompDisplay *d = (CompDisplay *) closure; + d->priv->handlePingTimeout(); + return true; } -static Bool -pingTimeout (void *closure) + +bool +setDisplayOption (CompObject *object, + const char *name, + CompOptionValue *value) { - CompDisplay *d = (CompDisplay *) closure; - CompScreen *s; - CompWindow *w; - XEvent ev; - int ping = d->lastPing + 1; + return ((CompDisplay *) object)->setOption (name, value); +} - ev.type = ClientMessage; - ev.xclient.window = 0; - ev.xclient.message_type = d->wmProtocolsAtom; - ev.xclient.format = 32; - ev.xclient.data.l[0] = d->wmPingAtom; - ev.xclient.data.l[1] = ping; - ev.xclient.data.l[2] = 0; - ev.xclient.data.l[3] = 0; - ev.xclient.data.l[4] = 0; - for (s = d->screens; s; s = s->next) - { - for (w = s->windows; w; w = w->next) - { - if (w->attrib.map_state != IsViewable) - continue; +static const int maskTable[] = { + ShiftMask, LockMask, ControlMask, Mod1Mask, + Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask +}; +static const int maskTableSize = sizeof (maskTable) / sizeof (int); - if (!(w->type & CompWindowTypeNormalMask)) - continue; +static int errors = 0; - if (w->protocols & CompWindowProtocolPingMask) - { - if (w->transientFor) - continue; +static int +errorHandler (Display *dpy, + XErrorEvent *e) +{ - if (w->lastPong < d->lastPing) - { - if (w->alive) - { - w->alive = FALSE; - w->paint.brightness = 0xa8a8; - w->paint.saturation = 0; - - if (w->closeRequests) - { - toolkitAction (s, - d->toolkitActionForceQuitDialogAtom, - w->lastCloseRequestTime, - w->id, - TRUE, - 0, - 0); - - w->closeRequests = 0; - } - - addWindowDamage (w); - } - } +#ifdef DEBUG + char str[128]; +#endif - ev.xclient.window = w->id; - ev.xclient.data.l[2] = w->id; + errors++; - XSendEvent (d->display, w->id, FALSE, NoEventMask, &ev); - } - } - } +#ifdef DEBUG + XGetErrorDatabaseText (dpy, "XlibMessage", "XError", "", str, 128); + fprintf (stderr, "%s", str); - d->lastPing = ping; + XGetErrorText (dpy, e->error_code, str, 128); + fprintf (stderr, ": %s\n ", str); - return TRUE; + XGetErrorDatabaseText (dpy, "XlibMessage", "MajorCode", "%d", str, 128); + fprintf (stderr, str, e->request_code); + + sprintf (str, "%d", e->request_code); + XGetErrorDatabaseText (dpy, "XRequest", str, "", str, 128); + if (strcmp (str, "")) + fprintf (stderr, " (%s)", str); + fprintf (stderr, "\n "); + + XGetErrorDatabaseText (dpy, "XlibMessage", "MinorCode", "%d", str, 128); + fprintf (stderr, str, e->minor_code); + fprintf (stderr, "\n "); + + XGetErrorDatabaseText (dpy, "XlibMessage", "ResourceID", "%d", str, 128); + fprintf (stderr, str, e->resourceid); + fprintf (stderr, "\n"); + + /* abort (); */ +#endif + + return 0; } -Bool -setDisplayOption (CompPlugin *plugin, - CompDisplay *display, - const char *name, - CompOptionValue *value) +int +compCheckForError (Display *dpy) { - CompOption *o; - int index; + int e; - o = compFindOption (display->opt, NUM_OPTIONS (display), name, &index); - if (!o) - return FALSE; + XSync (dpy, FALSE); - switch (index) { - case COMP_DISPLAY_OPTION_ABI: - break; - case COMP_DISPLAY_OPTION_ACTIVE_PLUGINS: - if (compSetOptionList (o, value)) - { - display->dirtyPluginList = TRUE; - return TRUE; - } - break; - case COMP_DISPLAY_OPTION_TEXTURE_FILTER: - if (compSetIntOption (o, value)) - { - CompScreen *s; + e = errors; + errors = 0; - for (s = display->screens; s; s = s->next) - damageScreen (s); + return e; +} - if (!o->value.i) - display->textureFilter = GL_NEAREST; - else - display->textureFilter = GL_LINEAR; +/* add actions that should be automatically added as no screens + existed when they were initialized. */ +void +CompDisplay::addScreenActions (CompScreen *s) +{ + int i; - return TRUE; - } - break; - case COMP_DISPLAY_OPTION_PING_DELAY: - if (compSetIntOption (o, value)) - { - if (display->pingHandle) - compRemoveTimeout (display->pingHandle); + for (i = 0; i < COMP_DISPLAY_OPTION_NUM; i++) + { + if (!isActionOption (&priv->opt[i])) + continue; - display->pingHandle = - compAddTimeout (o->value.i, o->value.i + 500, - pingTimeout, display); - return TRUE; - } - break; - case COMP_DISPLAY_OPTION_AUDIBLE_BELL: - if (compSetBoolOption (o, value)) - { - setAudibleBell (display, o->value.b); - return TRUE; - } - break; - default: - if (compSetDisplayOption (display, o, value)) - return TRUE; - break; + if (priv->opt[i].value.action.state & CompActionStateAutoGrab) + s->addAction (&priv->opt[i].value.action); } - - return FALSE; } -static void -updatePlugins (CompDisplay *d) +Bool +setDisplayAction (CompDisplay *display, + CompOption *o, + CompOptionValue *value) { - CompOption *o; - CompPlugin *p, **pop = 0; - int nPop, i, j; + CompScreen *s; - d->dirtyPluginList = FALSE; + for (s = display->screens (); s; s = s->next) + if (!s->addAction (&value->action)) + break; - o = &d->opt[COMP_DISPLAY_OPTION_ACTIVE_PLUGINS]; + if (s) + { + CompScreen *failed = s; - /* The old plugin list always begins with the core plugin. To make sure - we don't unnecessarily unload plugins if the new plugin list does not - contain the core plugin, we have to use an offset */ - if (o->value.list.nValue > 0 && strcmp (o->value.list.value[0].s, "core")) - i = 0; - else - i = 1; + for (s = display->screens (); s && s != failed; s = s->next) + s->removeAction (&value->action); - /* j is initialized to 1 to make sure we never pop the core plugin */ - for (j = 1; j < d->plugin.list.nValue && i < o->value.list.nValue; i++, j++) + return FALSE; + } + else { - if (strcmp (d->plugin.list.value[j].s, o->value.list.value[i].s)) - break; + for (s = display->screens (); s; s = s->next) + s->removeAction (&o->value.action); } - nPop = d->plugin.list.nValue - j; + if (compSetActionOption (o, value)) + return TRUE; - if (nPop) + return FALSE; +} + +CompDisplay::CompDisplay () : + next (0), + screenPrivateIndices (0), + screenPrivateLen (0) +{ + WRAPABLE_INIT_HND(handleEvent); + WRAPABLE_INIT_HND(handleCompizEvent); + WRAPABLE_INIT_HND(fileToImage); + WRAPABLE_INIT_HND(imageToFile); + WRAPABLE_INIT_HND(matchInitExp); + WRAPABLE_INIT_HND(matchExpHandlerChanged); + WRAPABLE_INIT_HND(matchPropertyChanged); + WRAPABLE_INIT_HND(logMessage); + + priv = new PrivateDisplay (this); + assert (priv); +} + + +CompDisplay::~CompDisplay () +{ + while (priv->screens) + removeScreen (priv->screens); + + core->objectRemove (core, this); + + objectFiniPlugins (this); + + core->removeTimeout (priv->pingHandle); + + if (priv->snDisplay) + sn_display_unref (priv->snDisplay); + + XSync (priv->dpy, False); + XCloseDisplay (priv->dpy); + + XDestroyRegion (mOutputRegion); + XDestroyRegion (mTmpRegion); + + + compFiniDisplayOptions (this, priv->opt, COMP_DISPLAY_OPTION_NUM); + + compFiniOptionValue (&priv->plugin, CompOptionTypeList); + + if (priv->modMap) + XFreeModifiermap (priv->modMap); + + if (priv->screenInfo) + XFree (priv->screenInfo); + + if (screenPrivateIndices) + free (screenPrivateIndices); + + if (privates) + free (privates); + + delete priv; +} + +bool +CompDisplay::init (const char *name) +{ + CompPrivate *privates; + Window focus; + int revertTo, i; + int compositeMajor, compositeMinor; + int fixesMinor; + int xkbOpcode; + int firstScreen, lastScreen; + + if (displayPrivateLen) { - pop = (CompPlugin **) malloc (sizeof (CompPlugin *) * nPop); - if (!pop) + privates = + (CompPrivate *) malloc (displayPrivateLen * sizeof (CompPrivate)); + if (!privates) { - (*core.setOptionForPlugin) (&d->base, "core", o->name, &d->plugin); - return; + return false; } } + else + privates = 0; - for (j = 0; j < nPop; j++) + compObjectInit (this, privates, COMP_OBJECT_TYPE_DISPLAY); + + mTmpRegion = XCreateRegion (); + if (!mTmpRegion) + return false; + + mOutputRegion = XCreateRegion (); + if (!mOutputRegion) { - pop[j] = popPlugin (); - d->plugin.list.nValue--; - free (d->plugin.list.value[d->plugin.list.nValue].s); + XDestroyRegion (mTmpRegion); + return false; } - for (; i < o->value.list.nValue; i++) + priv->plugin.list.type = CompOptionTypeString; + priv->plugin.list.nValue = 1; + priv->plugin.list.value = + (CompOptionValue *) malloc (sizeof (CompOptionValue)); + + if (!priv->plugin.list.value) { + return false; + } + + priv->plugin.list.value->s = strdup ("core"); + if (!priv->plugin.list.value->s) { + free (priv->plugin.list.value); + return false; + } + + priv->dpy = XOpenDisplay (name); + if (!priv->dpy) { - p = 0; - for (j = 0; j < nPop; j++) - { - if (pop[j] && strcmp (pop[j]->vTable->name, - o->value.list.value[i].s) == 0) - { - if (pushPlugin (pop[j])) - { - p = pop[j]; - pop[j] = 0; - break; - } - } - } + compLogMessage (this, "core", CompLogLevelFatal, + "Couldn't open display %s", XDisplayName (name)); + return false; + } - if (p == 0) - { - p = loadPlugin (o->value.list.value[i].s); - if (p) - { - if (!pushPlugin (p)) - { - unloadPlugin (p); - p = 0; - } - } - } +// priv->connection = XGetXCBConnection (priv->dpy); - if (p) - { - CompOptionValue *value; + if (!compInitDisplayOptionsFromMetadata (this, + &coreMetadata, + coreDisplayOptionInfo, + priv->opt, + COMP_DISPLAY_OPTION_NUM)) + return true; - value = (CompOptionValue *) realloc (d->plugin.list.value, sizeof (CompOptionValue) * - (d->plugin.list.nValue + 1)); - if (value) - { - value[d->plugin.list.nValue].s = strdup (p->vTable->name); + priv->opt[COMP_DISPLAY_OPTION_ABI].value.i = CORE_ABIVERSION; - d->plugin.list.value = value; - d->plugin.list.nValue++; - } - else - { - p = popPlugin (); - unloadPlugin (p); - } - } - } + snprintf (priv->displayString, 255, "DISPLAY=%s", + DisplayString (priv->dpy)); - for (j = 0; j < nPop; j++) +#ifdef DEBUG + XSynchronize (priv->dpy, TRUE); +#endif + + priv->initAtoms (); + + XSetErrorHandler (errorHandler); + + updateModifierMappings (); + + priv->snDisplay = sn_display_new (priv->dpy, NULL, NULL); + if (!priv->snDisplay) + return true; + + priv->lastPing = 1; + + if (!XQueryExtension (priv->dpy, + COMPOSITE_NAME, + &priv->compositeOpcode, + &priv->compositeEvent, + &priv->compositeError)) { - if (pop[j]) - unloadPlugin (pop[j]); + compLogMessage (this, "core", CompLogLevelFatal, + "No composite extension"); + return false; } - if (nPop) - free (pop); + XCompositeQueryVersion (priv->dpy, &compositeMajor, &compositeMinor); + if (compositeMajor == 0 && compositeMinor < 2) + { + compLogMessage (this, "core", CompLogLevelFatal, + "Old composite extension"); + return false; + } - (*core.setOptionForPlugin) (&d->base, "core", o->name, &d->plugin); -} + if (!XDamageQueryExtension (priv->dpy, &priv->damageEvent, + &priv->damageError)) + { + compLogMessage (this, "core", CompLogLevelFatal, + "No damage extension"); + return false; + } -static void -addTimeout (CompTimeout *timeout) -{ - CompTimeout *p = 0, *t; + if (!XSyncQueryExtension (priv->dpy, &priv->syncEvent, &priv->syncError)) + { + compLogMessage (this, "core", CompLogLevelFatal, + "No sync extension"); + return false; + } - for (t = core.timeouts; t; t = t->next) + if (!XFixesQueryExtension (priv->dpy, &priv->fixesEvent, &priv->fixesError)) { - if (timeout->minTime < t->minLeft) - break; + compLogMessage (this, "core", CompLogLevelFatal, + "No fixes extension"); + return false; + } - p = t; + XFixesQueryVersion (priv->dpy, &priv->fixesVersion, &fixesMinor); + /* + if (d->fixesVersion < 5) + { + fprintf (stderr, "%s: Need fixes extension version 5 or later " + "for client-side cursor\n", programName); } + */ - timeout->next = t; - timeout->minLeft = timeout->minTime; - timeout->maxLeft = timeout->maxTime; + priv->randrExtension = XRRQueryExtension (priv->dpy, &priv->randrEvent, + &priv->randrError); - if (p) - p->next = timeout; + priv->shapeExtension = XShapeQueryExtension (priv->dpy, &priv->shapeEvent, + &priv->shapeError); + + priv->xkbExtension = XkbQueryExtension (priv->dpy, &xkbOpcode, + &priv->xkbEvent, &priv->xkbError, + NULL, NULL); + if (priv->xkbExtension) + { + XkbSelectEvents (priv->dpy, + XkbUseCoreKbd, + XkbBellNotifyMask | XkbStateNotifyMask, + XkbAllEventsMask); + } else - core.timeouts = timeout; -} + { + compLogMessage (this, "core", CompLogLevelFatal, + "No XKB extension"); -CompTimeoutHandle -compAddTimeout (int minTime, - int maxTime, - CallBackProc callBack, - void *closure) -{ - CompTimeout *timeout; + priv->xkbEvent = priv->xkbError = -1; + } - timeout = (CompTimeout *) malloc (sizeof (CompTimeout)); - if (!timeout) - return 0; + priv->xineramaExtension = XineramaQueryExtension (priv->dpy, + &priv->xineramaEvent, + &priv->xineramaError); - timeout->minTime = minTime; - timeout->maxTime = (maxTime >= minTime) ? maxTime : minTime; - timeout->callBack = callBack; - timeout->closure = closure; - timeout->handle = core.lastTimeoutHandle++; - if (core.lastTimeoutHandle == MAXSHORT) - core.lastTimeoutHandle = 1; + updateScreenInfo(); - addTimeout (timeout); + priv->escapeKeyCode = + XKeysymToKeycode (priv->dpy, XStringToKeysym ("Escape")); + priv->returnKeyCode = + XKeysymToKeycode (priv->dpy, XStringToKeysym ("Return")); - return timeout->handle; -} + /* TODO: bailout properly when objectInitPlugins fails */ + assert (objectInitPlugins (this)); -void * -compRemoveTimeout (CompTimeoutHandle handle) -{ - CompTimeout *p = 0, *t; - void *closure = NULL; + core->objectAdd (core, this); - for (t = core.timeouts; t; t = t->next) + if (onlyCurrentScreen) { - if (t->handle == handle) - break; + firstScreen = DefaultScreen (priv->dpy); + lastScreen = DefaultScreen (priv->dpy); + } + else + { + firstScreen = 0; + lastScreen = ScreenCount (priv->dpy) - 1; + } - p = t; + for (i = firstScreen; i <= lastScreen; i++) + { + addScreen (i); } - if (t) + if (!priv->screens) { - if (p) - p->next = t->next; - else - core.timeouts = t->next; + compLogMessage (this, "core", CompLogLevelFatal, + "No manageable screens found on display %s", + XDisplayName (name)); + return false; + } + + priv->setAudibleBell (priv->opt[COMP_DISPLAY_OPTION_AUDIBLE_BELL].value.b); + + XGetInputFocus (priv->dpy, &focus, &revertTo); + + /* move input focus to root window so that we get a FocusIn event when + moving it to the default window */ + XSetInputFocus (priv->dpy, priv->screens->root (), RevertToPointerRoot, + CurrentTime); - closure = t->closure; + if (focus == None || focus == PointerRoot) + { + priv->screens->focusDefaultWindow (); + } + else + { + CompWindow *w; - free (t); + w = findWindow (focus); + if (w) + { + w->moveInputFocusTo (); + } + else + priv->screens->focusDefaultWindow (); } - return closure; + priv->pingHandle = + core->addTimeout (priv->opt[COMP_DISPLAY_OPTION_PING_DELAY].value.i, + priv->opt[COMP_DISPLAY_OPTION_PING_DELAY].value.i + + 500, CompDisplay::pingTimeout, this); + + return true; } -CompWatchFdHandle -compAddWatchFd (int fd, - short int events, - CallBackProc callBack, - void *closure) +CompDisplay::Atoms +CompDisplay::atoms () +{ + return priv->atoms; +} + +Display * +CompDisplay::dpy () +{ + return priv->dpy; +} + +CompScreen * +CompDisplay::screens () +{ + return priv->screens; +} + +GLenum +CompDisplay::textureFilter () +{ + return priv->textureFilter; +} + +CompOption * +CompDisplay::getOption (const char *name) +{ + int index; + CompOption *o = compFindOption (priv->opt, NUM_OPTIONS (this), + name, &index); + return o; +} + +XineramaScreenInfo * +CompDisplay::screenInfo () { - CompWatchFd *watchFd; + return priv->screenInfo; +} - watchFd = (CompWatchFd *) malloc (sizeof (CompWatchFd)); - if (!watchFd) - return 0; +int +CompDisplay::nScreenInfo () +{ + return priv->nScreenInfo; +} + +bool +CompDisplay::XRandr () +{ + return priv->randrExtension; +} - watchFd->fd = fd; - watchFd->callBack = callBack; - watchFd->closure = closure; - watchFd->handle = core.lastWatchFdHandle++; +bool +CompDisplay::XShape () +{ + return priv->shapeExtension; +} + +SnDisplay * +CompDisplay::snDisplay () +{ + return priv->snDisplay; +} + +Window +CompDisplay::below () +{ + return priv->below; +} + +Window +CompDisplay::activeWindow () +{ + return priv->activeWindow; +} - if (core.lastWatchFdHandle == MAXSHORT) - core.lastWatchFdHandle = 1; +Window +CompDisplay::autoRaiseWindow () +{ + return priv->autoRaiseWindow; +} - watchFd->next = core.watchFds; - core.watchFds = watchFd; +XModifierKeymap * +CompDisplay::modMap () +{ + return priv->modMap; +} - core.nWatchFds++; +unsigned int +CompDisplay::ignoredModMask () +{ + return priv->ignoredModMask; +} - core.watchPollFds = (struct pollfd *) realloc (core.watchPollFds, - core.nWatchFds * sizeof (struct pollfd)); +const char * +CompDisplay::displayString () +{ + return priv->displayString; +} - core.watchPollFds[core.nWatchFds - 1].fd = fd; - core.watchPollFds[core.nWatchFds - 1].events = events; +unsigned int +CompDisplay::lastPing () +{ + return priv->lastPing; +} - return watchFd->handle; +CompWatchFdHandle +CompDisplay::getWatchFdHandle () +{ + return priv->watchFdHandle; } void -compRemoveWatchFd (CompWatchFdHandle handle) +CompDisplay::setWatchFdHandle (CompWatchFdHandle handle) { - CompWatchFd *p = 0, *w; - int i; + priv->watchFdHandle = handle; +} - for (i = core.nWatchFds - 1, w = core.watchFds; w; i--, w = w->next) +void +CompDisplay::updateScreenInfo () +{ + if (priv->xineramaExtension) { - if (w->handle == handle) - break; + if (priv->screenInfo) + XFree (priv->screenInfo); - p = w; + priv->nScreenInfo = 0; + priv->screenInfo = XineramaQueryScreens (priv->dpy, &priv->nScreenInfo); } +} - if (w) - { - if (p) - p->next = w->next; - else - core.watchFds = w->next; +bool +CompDisplay::addScreen (int screenNum) +{ + CompScreen *s, *prev; + Window rootDummy, childDummy; + int x, y, dummy; + unsigned int uDummy; - core.nWatchFds--; + s = new CompScreen (); + if (!s) + return false; - if (i < core.nWatchFds) - memmove (&core.watchPollFds[i], &core.watchPollFds[i + 1], - (core.nWatchFds - i) * sizeof (struct pollfd)); + for (prev = priv->screens; prev && prev->next; prev = prev->next); - free (w); + if (prev) + prev->next = s; + else + priv->screens = s; + + if (!s->init (this, screenNum)) + { + compLogMessage (this, "core", CompLogLevelError, + "Failed to manage screen: %d", screenNum); + if (prev) + prev->next = NULL; + else + priv->screens = NULL; } + + if (XQueryPointer (priv->dpy, XRootWindow (priv->dpy, screenNum), + &rootDummy, &childDummy, + &x, &y, &dummy, &dummy, &uDummy)) + { + lastPointerX = pointerX = x; + lastPointerY = pointerY = y; + } + return true; } -short int -compWatchFdEvents (CompWatchFdHandle handle) +void +CompDisplay::removeScreen (CompScreen *s) { - CompWatchFd *w; - int i; + CompScreen *p; + + for (p = priv->screens; p; p = p->next) + if (p->next == s) + break; - for (i = core.nWatchFds - 1, w = core.watchFds; w; i--, w = w->next) - if (w->handle == handle) - return core.watchPollFds[i].revents; + if (p) + p->next = s->next; + else + priv->screens = NULL; - return 0; + delete s; } -#define TIMEVALDIFF(tv1, tv2) \ - ((tv1)->tv_sec == (tv2)->tv_sec || (tv1)->tv_usec >= (tv2)->tv_usec) ? \ - ((((tv1)->tv_sec - (tv2)->tv_sec) * 1000000) + \ - ((tv1)->tv_usec - (tv2)->tv_usec)) / 1000 : \ - ((((tv1)->tv_sec - 1 - (tv2)->tv_sec) * 1000000) + \ - (1000000 + (tv1)->tv_usec - (tv2)->tv_usec)) / 1000 - -static int -getTimeToNextRedraw (CompScreen *s, - struct timeval *tv, - struct timeval *lastTv, - Bool idle) +void +PrivateDisplay::setAudibleBell (bool audible) { - int diff, next; + if (xkbExtension) + XkbChangeEnabledControls (dpy, + XkbUseCoreKbd, + XkbAudibleBellMask, + audible ? XkbAudibleBellMask : 0); +} - diff = TIMEVALDIFF (tv, lastTv); +void +PrivateDisplay::handlePingTimeout () +{ + CompScreen *s; + CompWindow *w; + XEvent ev; + int ping = lastPing + 1; - /* handle clock rollback */ - if (diff < 0) - diff = 0; + ev.type = ClientMessage; + ev.xclient.window = 0; + ev.xclient.message_type = atoms.wmProtocols; + ev.xclient.format = 32; + ev.xclient.data.l[0] = atoms.wmPing; + ev.xclient.data.l[1] = ping; + ev.xclient.data.l[2] = 0; + ev.xclient.data.l[3] = 0; + ev.xclient.data.l[4] = 0; - if (idle || - (s->getVideoSync && s->opt[COMP_SCREEN_OPTION_SYNC_TO_VBLANK].value.b)) + for (s = screens; s; s = s->next) { - if (s->timeMult > 1) + for (w = s->windows (); w; w = w->next) { - s->frameStatus = -1; - s->redrawTime = s->optimalRedrawTime; - s->timeMult--; + if (w->handlePingTimeout (lastPing)) + { + ev.xclient.window = w->id (); + ev.xclient.data.l[2] = w->id (); + + XSendEvent (dpy, w->id (), false, NoEventMask, &ev); + } } } - else - { - if (diff > s->redrawTime) + + lastPing = ping; +} + +bool +CompDisplay::setOption (const char *name, + CompOptionValue *value) +{ + CompOption *o; + int index; + + o = compFindOption (priv->opt, NUM_OPTIONS (this), + name, &index); + if (!o) + return false; + + switch (index) { + case COMP_DISPLAY_OPTION_ABI: + break; + case COMP_DISPLAY_OPTION_ACTIVE_PLUGINS: + if (compSetOptionList (o, value)) + { + priv->dirtyPluginList = true; + return true; + } + break; + case COMP_DISPLAY_OPTION_TEXTURE_FILTER: + if (compSetIntOption (o, value)) { - if (s->frameStatus > 0) - s->frameStatus = 0; + CompScreen *s; - next = s->optimalRedrawTime * (s->timeMult + 1); - if (diff > next) - { - s->frameStatus--; - if (s->frameStatus < -1) - { - s->timeMult++; - s->redrawTime = diff = next; - } - } + for (s = priv->screens; s; s = s->next) + s->damageScreen (); + + if (!o->value.i) + priv->textureFilter = GL_NEAREST; + else + priv->textureFilter = GL_LINEAR; + + return true; } - else if (diff < s->redrawTime) + break; + case COMP_DISPLAY_OPTION_PING_DELAY: + if (compSetIntOption (o, value)) { - if (s->frameStatus < 0) - s->frameStatus = 0; + if (priv->pingHandle) + core->removeTimeout (priv->pingHandle); - if (s->timeMult > 1) - { - next = s->optimalRedrawTime * (s->timeMult - 1); - if (diff < next) - { - s->frameStatus++; - if (s->frameStatus > 4) - { - s->timeMult--; - s->redrawTime = next; - } - } - } + priv->pingHandle = + core->addTimeout (o->value.i, o->value.i + 500, + CompDisplay::pingTimeout, priv->dpy); + return true; + } + break; + case COMP_DISPLAY_OPTION_AUDIBLE_BELL: + if (compSetBoolOption (o, value)) + { + priv->setAudibleBell (o->value.b); + return true; } + break; + default: + if (compSetDisplayOption (this, o, value)) + return true; + break; } - if (diff > s->redrawTime) - return 0; - - return s->redrawTime - diff; + return false; } -static const int maskTable[] = { - ShiftMask, LockMask, ControlMask, Mod1Mask, - Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask -}; -static const int maskTableSize = sizeof (maskTable) / sizeof (int); - void -updateModifierMappings (CompDisplay *d) +CompDisplay::updateModifierMappings () { unsigned int modMask[CompModNum]; int i, minKeycode, maxKeycode, keysymsPerKeycode = 0; @@ -1272,38 +1435,38 @@ updateModifierMappings (CompDisplay *d) for (i = 0; i < CompModNum; i++) modMask[i] = 0; - XDisplayKeycodes (d->display, &minKeycode, &maxKeycode); - key = XGetKeyboardMapping (d->display, + XDisplayKeycodes (priv->dpy, &minKeycode, &maxKeycode); + key = XGetKeyboardMapping (priv->dpy, minKeycode, (maxKeycode - minKeycode + 1), &keysymsPerKeycode); - if (d->modMap) - XFreeModifiermap (d->modMap); + if (priv->modMap) + XFreeModifiermap (priv->modMap); - d->modMap = XGetModifierMapping (d->display); - if (d->modMap && d->modMap->max_keypermod > 0) + priv->modMap = XGetModifierMapping (priv->dpy); + if (priv->modMap && priv->modMap->max_keypermod > 0) { KeySym keysym; int index, size, mask; - size = maskTableSize * d->modMap->max_keypermod; + size = maskTableSize * priv->modMap->max_keypermod; for (i = 0; i < size; i++) { - if (!d->modMap->modifiermap[i]) + if (!priv->modMap->modifiermap[i]) continue; index = 0; do { - keysym = XKeycodeToKeysym (d->display, - d->modMap->modifiermap[i], + keysym = XKeycodeToKeysym (priv->dpy, + priv->modMap->modifiermap[i], index++); } while (!keysym && index < keysymsPerKeycode); if (keysym) { - mask = maskTable[i / d->modMap->max_keypermod]; + mask = maskTable[i / priv->modMap->max_keypermod]; if (keysym == XK_Alt_L || keysym == XK_Alt_R) @@ -1346,18 +1509,18 @@ updateModifierMappings (CompDisplay *d) modMask[i] = CompNoMask; } - if (memcmp (modMask, d->modMask, sizeof (modMask))) + if (memcmp (modMask, priv->modMask, sizeof (modMask))) { CompScreen *s; - memcpy (d->modMask, modMask, sizeof (modMask)); + memcpy (priv->modMask, modMask, sizeof (modMask)); - d->ignoredModMask = LockMask | + priv->ignoredModMask = LockMask | (modMask[CompModNumLock] & ~CompNoMask) | (modMask[CompModScrollLock] & ~CompNoMask); - for (s = d->screens; s; s = s->next) - updatePassiveGrabs (s); + for (s = priv->screens; s; s = s->next) + s->updatePassiveGrabs (); } } @@ -1366,8 +1529,7 @@ updateModifierMappings (CompDisplay *d) } unsigned int -virtualToRealModMask (CompDisplay *d, - unsigned int modMask) +CompDisplay::virtualToRealModMask (unsigned int modMask) { int i; @@ -1376,7 +1538,7 @@ virtualToRealModMask (CompDisplay *d, if (modMask & virtualModMask[i]) { modMask &= ~virtualModMask[i]; - modMask |= d->modMask[i]; + modMask |= priv->modMask[i]; } } @@ -1384,18 +1546,17 @@ virtualToRealModMask (CompDisplay *d, } unsigned int -keycodeToModifiers (CompDisplay *d, - int keycode) +CompDisplay::keycodeToModifiers (int keycode) { unsigned int mods = 0; int mod, k; for (mod = 0; mod < maskTableSize; mod++) { - for (k = 0; k < d->modMap->max_keypermod; k++) + for (k = 0; k < priv->modMap->max_keypermod; k++) { - if (d->modMap->modifiermap[mod * d->modMap->max_keypermod + k] == - keycode) + if (priv->modMap->modifiermap[mod * + priv->modMap->max_keypermod + k] == keycode) mods |= maskTable[mod]; } } @@ -1403,1655 +1564,1197 @@ keycodeToModifiers (CompDisplay *d, return mods; } -static int -doPoll (int timeout) +void +CompDisplay::processEvents () { - int rv; - - rv = poll (core.watchPollFds, core.nWatchFds, timeout); - if (rv) - { - CompWatchFd *w; - int i; - - for (i = core.nWatchFds - 1, w = core.watchFds; w; i--, w = w->next) - { - if (core.watchPollFds[i].revents != 0 && w->callBack) - (*w->callBack) (w->closure); - } - } + XEvent event; - return rv; -} + if (priv->dirtyPluginList) + priv->updatePlugins (); -static void -handleTimeouts (struct timeval *tv) -{ - CompTimeout *t; - int timeDiff; + while (XPending (priv->dpy)) + { + XNextEvent (priv->dpy, &event); - timeDiff = TIMEVALDIFF (tv, &core.lastTimeout); + switch (event.type) { + case ButtonPress: + case ButtonRelease: + pointerX = event.xbutton.x_root; + pointerY = event.xbutton.y_root; + break; + case KeyPress: + case KeyRelease: + pointerX = event.xkey.x_root; + pointerY = event.xkey.y_root; + break; + case MotionNotify: + pointerX = event.xmotion.x_root; + pointerY = event.xmotion.y_root; + break; + case EnterNotify: + case LeaveNotify: + pointerX = event.xcrossing.x_root; + pointerY = event.xcrossing.y_root; + break; + case ClientMessage: + if (event.xclient.message_type == priv->atoms.xdndPosition) + { + pointerX = event.xclient.data.l[2] >> 16; + pointerY = event.xclient.data.l[2] & 0xffff; + } + default: + break; + } - /* handle clock rollback */ - if (timeDiff < 0) - timeDiff = 0; + sn_display_process_event (priv->snDisplay, &event); - for (t = core.timeouts; t; t = t->next) - { - t->minLeft -= timeDiff; - t->maxLeft -= timeDiff; - } + inHandleEvent = true; + handleEvent (&event); + inHandleEvent = false; - while (core.timeouts && core.timeouts->minLeft <= 0) - { - t = core.timeouts; - if ((*t->callBack) (t->closure)) - { - core.timeouts = t->next; - addTimeout (t); - } - else - { - core.timeouts = t->next; - free (t); - } + lastPointerX = pointerX; + lastPointerY = pointerY; } - - core.lastTimeout = *tv; } -static void -waitForVideoSync (CompScreen *s) +void +PrivateDisplay::updatePlugins () { - unsigned int sync; + CompOption *o; + CompPlugin *p, **pop = 0; + int nPop, i, j; - if (!s->opt[COMP_SCREEN_OPTION_SYNC_TO_VBLANK].value.b) - return; + dirtyPluginList = false; - if (s->getVideoSync) - { - glFlush (); + o = &opt[COMP_DISPLAY_OPTION_ACTIVE_PLUGINS]; - (*s->getVideoSync) (&sync); - (*s->waitVideoSync) (2, (sync + 1) % 2, &sync); - } -} + /* The old plugin list always begins with the core plugin. To make sure + we don't unnecessarily unload plugins if the new plugin list does not + contain the core plugin, we have to use an offset */ + if (o->value.list.nValue > 0 && strcmp (o->value.list.value[0].s, "core")) + i = 0; + else + i = 1; + /* j is initialized to 1 to make sure we never pop the core plugin */ + for (j = 1; j < plugin.list.nValue && + i < o->value.list.nValue; i++, j++) + { + if (strcmp (plugin.list.value[j].s, o->value.list.value[i].s)) + break; + } -void -paintScreen (CompScreen *s, - CompOutput *outputs, - int numOutput, - unsigned int mask) -{ - XRectangle r; - int i; + nPop = plugin.list.nValue - j; - for (i = 0; i < numOutput; i++) + if (nPop) { - targetScreen = s; - targetOutput = &outputs[i]; - - r.x = outputs[i].region.extents.x1; - r.y = s->height - outputs[i].region.extents.y2; - r.width = outputs[i].width; - r.height = outputs[i].height; - - if (s->lastViewport.x != r.x || - s->lastViewport.y != r.y || - s->lastViewport.width != r.width || - s->lastViewport.height != r.height) - { - glViewport (r.x, r.y, r.width, r.height); - s->lastViewport = r; - } - - if (mask & COMP_SCREEN_DAMAGE_ALL_MASK) - { - (*s->paintOutput) (s, - &defaultScreenPaintAttrib, - &identity, - &outputs[i].region, &outputs[i], - PAINT_SCREEN_REGION_MASK | - PAINT_SCREEN_FULL_MASK); - } - else if (mask & COMP_SCREEN_DAMAGE_REGION_MASK) + pop = (CompPlugin **) malloc (sizeof (CompPlugin *) * nPop); + if (!pop) { - XIntersectRegion (core.tmpRegion, - &outputs[i].region, - core.outputRegion); - - if (!(*s->paintOutput) (s, - &defaultScreenPaintAttrib, - &identity, - core.outputRegion, &outputs[i], - PAINT_SCREEN_REGION_MASK)) - { - (*s->paintOutput) (s, - &defaultScreenPaintAttrib, - &identity, - &outputs[i].region, &outputs[i], - PAINT_SCREEN_FULL_MASK); - - XUnionRegion (core.tmpRegion, - &outputs[i].region, - core.tmpRegion); - - } + core->setOptionForPlugin (display, "core", o->name, &plugin); + return; } } -} -void -eventLoop (void) -{ - XEvent event; - int timeDiff; - struct timeval tv; - CompDisplay *d; - CompScreen *s; - CompWindow *w; - CompTimeout *t; - int time, timeToNextRedraw = 0; - unsigned int damageMask, mask; - - for (d = core.displays; d; d = d->next) - d->watchFdHandle = - compAddWatchFd (ConnectionNumber (d->display), POLLIN, NULL, NULL); - - for (;;) + for (j = 0; j < nPop; j++) { - if (restartSignal || shutDown) - break; - - for (d = core.displays; d; d = d->next) - { - if (d->dirtyPluginList) - updatePlugins (d); - - while (XPending (d->display)) - { - XNextEvent (d->display, &event); - - switch (event.type) { - case ButtonPress: - case ButtonRelease: - pointerX = event.xbutton.x_root; - pointerY = event.xbutton.y_root; - break; - case KeyPress: - case KeyRelease: - pointerX = event.xkey.x_root; - pointerY = event.xkey.y_root; - break; - case MotionNotify: - pointerX = event.xmotion.x_root; - pointerY = event.xmotion.y_root; - break; - case EnterNotify: - case LeaveNotify: - pointerX = event.xcrossing.x_root; - pointerY = event.xcrossing.y_root; - break; - case ClientMessage: - if (event.xclient.message_type == d->xdndPositionAtom) - { - pointerX = event.xclient.data.l[2] >> 16; - pointerY = event.xclient.data.l[2] & 0xffff; - } - default: - break; - } - - sn_display_process_event (d->snDisplay, &event); - - inHandleEvent = TRUE; - - (*d->handleEvent) (d, &event); - - inHandleEvent = FALSE; - - lastPointerX = pointerX; - lastPointerY = pointerY; - } - } + pop[j] = popPlugin (); + plugin.list.nValue--; + free (plugin.list.value[plugin.list.nValue].s); + } - for (d = core.displays; d; d = d->next) + for (; i < o->value.list.nValue; i++) + { + p = 0; + for (j = 0; j < nPop; j++) { - for (s = d->screens; s; s = s->next) + if (pop[j] && strcmp (pop[j]->vTable->name (), + o->value.list.value[i].s) == 0) { - if (s->damageMask) - { - finishScreenDrawing (s); - } - else + if (pushPlugin (pop[j])) { - s->idle = TRUE; + p = pop[j]; + pop[j] = 0; + break; } } } - damageMask = 0; - timeToNextRedraw = MAXSHORT; - - for (d = core.displays; d; d = d->next) + if (p == 0) { - for (s = d->screens; s; s = s->next) + p = loadPlugin (o->value.list.value[i].s); + if (p) { - if (!s->damageMask) - continue; - - if (!damageMask) + if (!pushPlugin (p)) { - gettimeofday (&tv, 0); - damageMask |= s->damageMask; + unloadPlugin (p); + p = 0; } - - s->timeLeft = getTimeToNextRedraw (s, &tv, &s->lastRedraw, - s->idle); - if (s->timeLeft < timeToNextRedraw) - timeToNextRedraw = s->timeLeft; } } - if (damageMask) + if (p) { - time = timeToNextRedraw; - if (time) - time = doPoll (time); - - if (time == 0) - { - gettimeofday (&tv, 0); - - if (core.timeouts) - handleTimeouts (&tv); + CompOptionValue *value; - for (d = core.displays; d; d = d->next) - { - for (s = d->screens; s; s = s->next) - { - if (!s->damageMask || s->timeLeft > timeToNextRedraw) - continue; - - targetScreen = s; - - timeDiff = TIMEVALDIFF (&tv, &s->lastRedraw); - - /* handle clock rollback */ - if (timeDiff < 0) - timeDiff = 0; - - makeScreenCurrent (s); - - if (s->slowAnimations) - { - (*s->preparePaintScreen) (s, - s->idle ? 2 : - (timeDiff * 2) / - s->redrawTime); - } - else - (*s->preparePaintScreen) (s, - s->idle ? s->redrawTime : - timeDiff); - - /* substract top most overlay window region */ - if (s->overlayWindowCount) - { - for (w = s->reverseWindows; w; w = w->prev) - { - if (w->destroyed || w->invisible) - continue; - - if (!w->redirected) - XSubtractRegion (s->damage, w->region, - s->damage); - - break; - } - - if (s->damageMask & COMP_SCREEN_DAMAGE_ALL_MASK) - { - s->damageMask &= ~COMP_SCREEN_DAMAGE_ALL_MASK; - s->damageMask |= - COMP_SCREEN_DAMAGE_REGION_MASK; - } - } - - if (s->damageMask & COMP_SCREEN_DAMAGE_REGION_MASK) - { - XIntersectRegion (s->damage, &s->region, - core.tmpRegion); - - if (core.tmpRegion->numRects == 1 && - core.tmpRegion->rects->x1 == 0 && - core.tmpRegion->rects->y1 == 0 && - core.tmpRegion->rects->x2 == s->width && - core.tmpRegion->rects->y2 == s->height) - damageScreen (s); - } - - EMPTY_REGION (s->damage); - - mask = s->damageMask; - s->damageMask = 0; - - if (s->clearBuffers) - { - if (mask & COMP_SCREEN_DAMAGE_ALL_MASK) - glClear (GL_COLOR_BUFFER_BIT); - } - - if (s->opt[COMP_SCREEN_OPTION_FORCE_INDEPENDENT].value.b - || !s->hasOverlappingOutputs) - (*s->paintScreen) (s, s->outputDev, - s->nOutputDev, - mask); - else - (*s->paintScreen) (s, &s->fullscreenOutput, 1, - mask); - - targetScreen = NULL; - targetOutput = &s->outputDev[0]; - - waitForVideoSync (s); - - if (mask & COMP_SCREEN_DAMAGE_ALL_MASK) - { - glXSwapBuffers (d->display, s->output); - } - else - { - BoxPtr pBox; - int nBox, y; - - pBox = core.tmpRegion->rects; - nBox = core.tmpRegion->numRects; - - if (s->copySubBuffer) - { - while (nBox--) - { - y = s->height - pBox->y2; - - (*s->copySubBuffer) (d->display, - s->output, - pBox->x1, y, - pBox->x2 - pBox->x1, - pBox->y2 - pBox->y1); - - pBox++; - } - } - else - { - glEnable (GL_SCISSOR_TEST); - glDrawBuffer (GL_FRONT); - - while (nBox--) - { - y = s->height - pBox->y2; - - glBitmap (0, 0, 0, 0, - pBox->x1 - s->rasterX, - y - s->rasterY, - NULL); - - s->rasterX = pBox->x1; - s->rasterY = y; - - glScissor (pBox->x1, y, - pBox->x2 - pBox->x1, - pBox->y2 - pBox->y1); - - glCopyPixels (pBox->x1, y, - pBox->x2 - pBox->x1, - pBox->y2 - pBox->y1, - GL_COLOR); - - pBox++; - } - - glDrawBuffer (GL_BACK); - glDisable (GL_SCISSOR_TEST); - glFlush (); - } - } - - s->lastRedraw = tv; - - (*s->donePaintScreen) (s); - - /* remove destroyed windows */ - while (s->pendingDestroys) - { - CompWindow *w; - - for (w = s->windows; w; w = w->next) - { - if (w->destroyed) - { - addWindowDamage (w); - removeWindow (w); - break; - } - } - - s->pendingDestroys--; - } - - s->idle = FALSE; - } - } - } - } - else - { - if (core.timeouts) + value = (CompOptionValue *) + realloc (plugin.list.value, sizeof (CompOptionValue) * + (plugin.list.nValue + 1)); + if (value) { - if (core.timeouts->minLeft > 0) - { - t = core.timeouts; - time = t->maxLeft; - while (t && t->minLeft <= time) - { - if (t->maxLeft < time) - time = t->maxLeft; - t = t->next; - } - doPoll (time); - } - - gettimeofday (&tv, 0); + value[plugin.list.nValue].s = strdup (p->vTable->name ()); - handleTimeouts (&tv); + plugin.list.value = value; + plugin.list.nValue++; } else { - doPoll (-1); + p = popPlugin (); + unloadPlugin (p); } } } - for (d = core.displays; d; d = d->next) - compRemoveWatchFd (d->watchFdHandle); -} - -static int errors = 0; - -static int -errorHandler (Display *dpy, - XErrorEvent *e) -{ - -#ifdef DEBUG - char str[128]; -#endif - - errors++; - -#ifdef DEBUG - XGetErrorDatabaseText (dpy, "XlibMessage", "XError", "", str, 128); - fprintf (stderr, "%s", str); - - XGetErrorText (dpy, e->error_code, str, 128); - fprintf (stderr, ": %s\n ", str); - - XGetErrorDatabaseText (dpy, "XlibMessage", "MajorCode", "%d", str, 128); - fprintf (stderr, str, e->request_code); + for (j = 0; j < nPop; j++) + { + if (pop[j]) + unloadPlugin (pop[j]); + } - sprintf (str, "%d", e->request_code); - XGetErrorDatabaseText (dpy, "XRequest", str, "", str, 128); - if (strcmp (str, "")) - fprintf (stderr, " (%s)", str); - fprintf (stderr, "\n "); + if (nPop) + free (pop); - XGetErrorDatabaseText (dpy, "XlibMessage", "MinorCode", "%d", str, 128); - fprintf (stderr, str, e->minor_code); - fprintf (stderr, "\n "); + core->setOptionForPlugin (display, "core", o->name, &plugin); +} - XGetErrorDatabaseText (dpy, "XlibMessage", "ResourceID", "%d", str, 128); - fprintf (stderr, str, e->resourceid); - fprintf (stderr, "\n"); +CompScreen * +CompDisplay::findScreen (Window root) +{ + CompScreen *s; - /* abort (); */ -#endif + for (s = priv->screens; s; s = s->next) + { + if (s->root () == root) + return s; + } return 0; } -int -compCheckForError (Display *dpy) +void +CompDisplay::forEachWindow (ForEachWindowProc proc, + void *closure) { - int e; + CompScreen *s; - XSync (dpy, FALSE); + for (s = priv->screens; s; s = s->next) + s->forEachWindow (proc, closure); +} - e = errors; - errors = 0; +CompWindow * +CompDisplay::findWindow (Window id) +{ + CompScreen *s; + CompWindow *w; - return e; + for (s = priv->screens; s; s = s->next) + { + w = s->findWindow (id); + if (w) + return w; + } + + return 0; } -/* add actions that should be automatically added as no screens - existed when they were initialized. */ -static void -addScreenActions (CompScreen *s) +CompWindow * +CompDisplay::findTopLevelWindow (Window id) { - int i; + CompScreen *s; + CompWindow *w; - for (i = 0; i < COMP_DISPLAY_OPTION_NUM; i++) + for (s = priv->screens; s; s = s->next) { - if (!isActionOption (&s->display->opt[i])) - continue; - - if (s->display->opt[i].value.action.state & CompActionStateAutoGrab) - addScreenAction (s, &s->display->opt[i].value.action); + w = s->findTopLevelWindow (id); + if (w) + return w; } + + return 0; } -void -addScreenToDisplay (CompDisplay *display, - CompScreen *s) +static CompScreen * +findScreenForSelection (CompDisplay *display, + Window owner, + Atom selection) { - CompScreen *prev; - - for (prev = display->screens; prev && prev->next; prev = prev->next); + CompScreen *s; - if (prev) - prev->next = s; - else - display->screens = s; + for (s = display->screens(); s; s = s->next) + { + if (s->selectionWindow () == owner && s->selectionAtom () == selection) + return s; + } - addScreenActions (s); + return NULL; } -static void -freeDisplay (CompDisplay *d) +/* from fvwm2, Copyright Matthias Clasen, Dominik Vogt */ +static bool +convertProperty (CompDisplay *display, + CompScreen *screen, + Window w, + Atom target, + Atom property) { - compFiniDisplayOptions (d, d->opt, COMP_DISPLAY_OPTION_NUM); - compFiniOptionValue (&d->plugin, CompOptionTypeList); +#define N_TARGETS 4 - if (d->modMap) - XFreeModifiermap (d->modMap); + Atom conversionTargets[N_TARGETS]; + long icccmVersion[] = { 2, 0 }; + Time time = screen->selectionTimestamp (); - if (d->screenInfo) - XFree (d->screenInfo); + conversionTargets[0] = display->atoms().targets; + conversionTargets[1] = display->atoms().multiple; + conversionTargets[2] = display->atoms().timestamp; + conversionTargets[3] = display->atoms().version; - if (d->screenPrivateIndices) - free (d->screenPrivateIndices); + if (target == display->atoms().targets) + XChangeProperty (display->dpy(), w, property, + XA_ATOM, 32, PropModeReplace, + (unsigned char *) conversionTargets, N_TARGETS); + else if (target == display->atoms().timestamp) + XChangeProperty (display->dpy(), w, property, + XA_INTEGER, 32, PropModeReplace, + (unsigned char *) &time, 1); + else if (target == display->atoms().version) + XChangeProperty (display->dpy(), w, property, + XA_INTEGER, 32, PropModeReplace, + (unsigned char *) icccmVersion, 2); + else + return false; - if (d->base.privates) - free (d->base.privates); + /* Be sure the PropertyNotify has arrived so we + * can send SelectionNotify + */ + XSync (display->dpy (), FALSE); - free (d); + return true; } -Bool -addDisplay (const char *name) +/* from fvwm2, Copyright Matthias Clasen, Dominik Vogt */ +void +PrivateDisplay::handleSelectionRequest (XEvent *event) { - CompDisplay *d; - CompPrivate *privates; - Display *dpy; - Window focus; - int revertTo, i; - int compositeMajor, compositeMinor; - int fixesMinor; - int xkbOpcode; - int firstScreen, lastScreen; + XSelectionEvent reply; + CompScreen *screen; - d = (CompDisplay *) malloc (sizeof (CompDisplay)); - if (!d) - return FALSE; + screen = findScreenForSelection (display, + event->xselectionrequest.owner, + event->xselectionrequest.selection); + if (!screen) + return; - if (displayPrivateLen) + reply.type = SelectionNotify; + reply.display = dpy; + reply.requestor = event->xselectionrequest.requestor; + reply.selection = event->xselectionrequest.selection; + reply.target = event->xselectionrequest.target; + reply.property = None; + reply.time = event->xselectionrequest.time; + + if (event->xselectionrequest.target == atoms.multiple) { - privates = (CompPrivate *) malloc (displayPrivateLen * sizeof (CompPrivate)); - if (!privates) + if (event->xselectionrequest.property != None) { - free (d); - return FALSE; - } - } - else - privates = 0; + Atom type, *adata; + int i, format; + unsigned long num, rest; + unsigned char *data; + + if (XGetWindowProperty (dpy, + event->xselectionrequest.requestor, + event->xselectionrequest.property, + 0, 256, FALSE, + atoms.atomPair, + &type, &format, &num, &rest, + &data) != Success) + return; - compObjectInit (&d->base, privates, COMP_OBJECT_TYPE_DISPLAY); + /* FIXME: to be 100% correct, should deal with rest > 0, + * but since we have 4 possible targets, we will hardly ever + * meet multiple requests with a length > 8 + */ + adata = (Atom *) data; + i = 0; + while (i < (int) num) + { + if (!convertProperty (display, screen, + event->xselectionrequest.requestor, + adata[i], adata[i + 1])) + adata[i + 1] = None; - d->next = NULL; - d->screens = NULL; + i += 2; + } - d->watchFdHandle = 0; + XChangeProperty (dpy, + event->xselectionrequest.requestor, + event->xselectionrequest.property, + atoms.atomPair, + 32, PropModeReplace, data, num); + } + } + else + { + if (event->xselectionrequest.property == None) + event->xselectionrequest.property = event->xselectionrequest.target; - d->screenPrivateIndices = 0; - d->screenPrivateLen = 0; + if (convertProperty (display, screen, + event->xselectionrequest.requestor, + event->xselectionrequest.target, + event->xselectionrequest.property)) + reply.property = event->xselectionrequest.property; + } - d->edgeDelayHandle = 0; + XSendEvent (dpy, + event->xselectionrequest.requestor, + FALSE, 0L, (XEvent *) &reply); +} - d->logMessage = logMessage; +void +PrivateDisplay::handleSelectionClear (XEvent *event) +{ + /* We need to unmanage the screen on which we lost the selection */ + CompScreen *screen; - d->modMap = 0; + screen = findScreenForSelection (display, + event->xselectionclear.window, + event->xselectionclear.selection); - for (i = 0; i < CompModNum; i++) - d->modMask[i] = CompNoMask; + if (screen) + shutDown = TRUE; +} - d->ignoredModMask = LockMask; - compInitOptionValue (&d->plugin); +void +CompDisplay::clearTargetOutput (unsigned int mask) +{ + if (targetScreen) + targetScreen->clearOutput (targetOutput, mask); +} - d->plugin.list.type = CompOptionTypeString; - d->plugin.list.nValue = 1; - d->plugin.list.value = (CompOptionValue *) malloc (sizeof (CompOptionValue)); +#define HOME_IMAGEDIR ".compiz/images" - if (!d->plugin.list.value) { - free (d); - return FALSE; - } +bool +CompDisplay::readImageFromFile (const char *name, + int *width, + int *height, + void **data) +{ + Bool status; + int stride; - d->plugin.list.value->s = strdup ("core"); - if (!d->plugin.list.value->s) { - free (d->plugin.list.value); - free (d); - return FALSE; - } + status = fileToImage (NULL, name, width, height, &stride, data); + if (!status) + { + char *home; - d->dirtyPluginList = TRUE; + home = getenv ("HOME"); + if (home) + { + char *path; - d->textureFilter = GL_LINEAR; - d->below = None; + path = (char *) malloc (strlen (home) + strlen (HOME_IMAGEDIR) + 2); + if (path) + { + sprintf (path, "%s/%s", home, HOME_IMAGEDIR); + status = fileToImage (path, name, width, height, &stride, data); - d->activeWindow = 0; + free (path); - d->autoRaiseHandle = 0; - d->autoRaiseWindow = None; + if (status) + return TRUE; + } + } - d->display = dpy = XOpenDisplay (name); - if (!d->display) - { - compLogMessage (d, "core", CompLogLevelFatal, - "Couldn't open display %s", XDisplayName (name)); - return FALSE; + status = fileToImage (IMAGEDIR, name, width, height, &stride, data); } - // d->connection = XGetXCBConnection (dpy); + return status; +} - if (!compInitDisplayOptionsFromMetadata (d, - &coreMetadata, - coreDisplayOptionInfo, - d->opt, - COMP_DISPLAY_OPTION_NUM)) - return FALSE; +bool +CompDisplay::writeImageToFile (const char *path, + const char *name, + const char *format, + int width, + int height, + void *data) +{ + return imageToFile (path, name, format, width, height, width * 4, data); +} - d->opt[COMP_DISPLAY_OPTION_ABI].value.i = CORE_ABIVERSION; - snprintf (d->displayString, 255, "DISPLAY=%s", DisplayString (dpy)); +CompCursor * +CompDisplay::findCursor () +{ + CompScreen *s; -#ifdef DEBUG - XSynchronize (dpy, TRUE); -#endif + for (s = priv->screens; s; s = s->next) + if (s->cursors ()) + return s->cursors (); - XSetErrorHandler (errorHandler); + return NULL; +} - updateModifierMappings (d); +Window +CompDisplay::getActiveWindow (Window root) +{ + Atom actual; + int result, format; + unsigned long n, left; + unsigned char *data; + Window w = None; - d->handleEvent = handleEvent; - d->handleCompizEvent = handleCompizEvent; + result = XGetWindowProperty (priv->dpy, root, + priv->atoms.winActive, 0L, 1L, FALSE, + XA_WINDOW, &actual, &format, + &n, &left, &data); - d->fileToImage = fileToImage; - d->imageToFile = imageToFile; + if (result == Success && n && data) + { + memcpy (&w, data, sizeof (Window)); + XFree (data); + } - d->matchInitExp = matchInitExp; - d->matchExpHandlerChanged = matchExpHandlerChanged; - d->matchPropertyChanged = matchPropertyChanged; + return w; +} - d->supportedAtom = XInternAtom (dpy, "_NET_SUPPORTED", 0); - d->supportingWmCheckAtom = XInternAtom (dpy, "_NET_SUPPORTING_WM_CHECK", 0); +void +PrivateDisplay::initAtoms () +{ + atoms.supported = XInternAtom (dpy, "_NET_SUPPORTED", 0); + atoms.supportingWmCheck = XInternAtom (dpy, "_NET_SUPPORTING_WM_CHECK", 0); - d->utf8StringAtom = XInternAtom (dpy, "UTF8_STRING", 0); + atoms.utf8String = XInternAtom (dpy, "UTF8_STRING", 0); - d->wmNameAtom = XInternAtom (dpy, "_NET_WM_NAME", 0); + atoms.wmName = XInternAtom (dpy, "_NET_WM_NAME", 0); - d->winTypeAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE", 0); - d->winTypeDesktopAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DESKTOP", + atoms.winType = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE", 0); + atoms.winTypeDesktop = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DESKTOP", 0); - d->winTypeDockAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DOCK", 0); - d->winTypeToolbarAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLBAR", + atoms.winTypeDock = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DOCK", 0); + atoms.winTypeToolbar = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLBAR", 0); - d->winTypeMenuAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_MENU", 0); - d->winTypeUtilAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_UTILITY", + atoms.winTypeMenu = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_MENU", 0); + atoms.winTypeUtil = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_UTILITY", 0); - d->winTypeSplashAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_SPLASH", 0); - d->winTypeDialogAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DIALOG", 0); - d->winTypeNormalAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NORMAL", 0); + atoms.winTypeSplash = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_SPLASH", 0); + atoms.winTypeDialog = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DIALOG", 0); + atoms.winTypeNormal = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NORMAL", 0); - d->winTypeDropdownMenuAtom = + atoms.winTypeDropdownMenu = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", 0); - d->winTypePopupMenuAtom = + atoms.winTypePopupMenu = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_POPUP_MENU", 0); - d->winTypeTooltipAtom = + atoms.winTypeTooltip = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLTIP", 0); - d->winTypeNotificationAtom = + atoms.winTypeNotification = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NOTIFICATION", 0); - d->winTypeComboAtom = + atoms.winTypeCombo = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_COMBO", 0); - d->winTypeDndAtom = + atoms.winTypeDnd = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DND", 0); - d->winOpacityAtom = XInternAtom (dpy, "_NET_WM_WINDOW_OPACITY", 0); - d->winBrightnessAtom = XInternAtom (dpy, "_NET_WM_WINDOW_BRIGHTNESS", 0); - d->winSaturationAtom = XInternAtom (dpy, "_NET_WM_WINDOW_SATURATION", 0); - - d->winActiveAtom = XInternAtom (dpy, "_NET_ACTIVE_WINDOW", 0); - - d->winDesktopAtom = XInternAtom (dpy, "_NET_WM_DESKTOP", 0); + atoms.winOpacity = XInternAtom (dpy, "_NET_WM_WINDOW_OPACITY", 0); + atoms.winBrightness = XInternAtom (dpy, "_NET_WM_WINDOW_BRIGHTNESS", 0); + atoms.winSaturation = XInternAtom (dpy, "_NET_WM_WINDOW_SATURATION", 0); - d->workareaAtom = XInternAtom (dpy, "_NET_WORKAREA", 0); + atoms.winActive = XInternAtom (dpy, "_NET_ACTIVE_WINDOW", 0); + atoms.winDesktop = XInternAtom (dpy, "_NET_WM_DESKTOP", 0); + atoms.workarea = XInternAtom (dpy, "_NET_WORKAREA", 0); - d->desktopViewportAtom = XInternAtom (dpy, "_NET_DESKTOP_VIEWPORT", 0); - d->desktopGeometryAtom = XInternAtom (dpy, "_NET_DESKTOP_GEOMETRY", 0); - d->currentDesktopAtom = XInternAtom (dpy, "_NET_CURRENT_DESKTOP", 0); - d->numberOfDesktopsAtom = XInternAtom (dpy, "_NET_NUMBER_OF_DESKTOPS", 0); + atoms.desktopViewport = XInternAtom (dpy, "_NET_DESKTOP_VIEWPORT", 0); + atoms.desktopGeometry = XInternAtom (dpy, "_NET_DESKTOP_GEOMETRY", 0); + atoms.currentDesktop = XInternAtom (dpy, "_NET_CURRENT_DESKTOP", 0); + atoms.numberOfDesktops = XInternAtom (dpy, "_NET_NUMBER_OF_DESKTOPS", 0); - d->winStateAtom = XInternAtom (dpy, "_NET_WM_STATE", 0); - d->winStateModalAtom = + atoms.winState = XInternAtom (dpy, "_NET_WM_STATE", 0); + atoms.winStateModal = XInternAtom (dpy, "_NET_WM_STATE_MODAL", 0); - d->winStateStickyAtom = + atoms.winStateSticky = XInternAtom (dpy, "_NET_WM_STATE_STICKY", 0); - d->winStateMaximizedVertAtom = + atoms.winStateMaximizedVert = XInternAtom (dpy, "_NET_WM_STATE_MAXIMIZED_VERT", 0); - d->winStateMaximizedHorzAtom = + atoms.winStateMaximizedHorz = XInternAtom (dpy, "_NET_WM_STATE_MAXIMIZED_HORZ", 0); - d->winStateShadedAtom = + atoms.winStateShaded = XInternAtom (dpy, "_NET_WM_STATE_SHADED", 0); - d->winStateSkipTaskbarAtom = + atoms.winStateSkipTaskbar = XInternAtom (dpy, "_NET_WM_STATE_SKIP_TASKBAR", 0); - d->winStateSkipPagerAtom = + atoms.winStateSkipPager = XInternAtom (dpy, "_NET_WM_STATE_SKIP_PAGER", 0); - d->winStateHiddenAtom = + atoms.winStateHidden = XInternAtom (dpy, "_NET_WM_STATE_HIDDEN", 0); - d->winStateFullscreenAtom = + atoms.winStateFullscreen = XInternAtom (dpy, "_NET_WM_STATE_FULLSCREEN", 0); - d->winStateAboveAtom = + atoms.winStateAbove = XInternAtom (dpy, "_NET_WM_STATE_ABOVE", 0); - d->winStateBelowAtom = + atoms.winStateBelow = XInternAtom (dpy, "_NET_WM_STATE_BELOW", 0); - d->winStateDemandsAttentionAtom = + atoms.winStateDemandsAttention = XInternAtom (dpy, "_NET_WM_STATE_DEMANDS_ATTENTION", 0); - d->winStateDisplayModalAtom = + atoms.winStateDisplayModal = XInternAtom (dpy, "_NET_WM_STATE_DISPLAY_MODAL", 0); - d->winActionMoveAtom = XInternAtom (dpy, "_NET_WM_ACTION_MOVE", 0); - d->winActionResizeAtom = + atoms.winActionMove = XInternAtom (dpy, "_NET_WM_ACTION_MOVE", 0); + atoms.winActionResize = XInternAtom (dpy, "_NET_WM_ACTION_RESIZE", 0); - d->winActionStickAtom = + atoms.winActionStick = XInternAtom (dpy, "_NET_WM_ACTION_STICK", 0); - d->winActionMinimizeAtom = + atoms.winActionMinimize = XInternAtom (dpy, "_NET_WM_ACTION_MINIMIZE", 0); - d->winActionMaximizeHorzAtom = + atoms.winActionMaximizeHorz = XInternAtom (dpy, "_NET_WM_ACTION_MAXIMIZE_HORZ", 0); - d->winActionMaximizeVertAtom = + atoms.winActionMaximizeVert = XInternAtom (dpy, "_NET_WM_ACTION_MAXIMIZE_VERT", 0); - d->winActionFullscreenAtom = + atoms.winActionFullscreen = XInternAtom (dpy, "_NET_WM_ACTION_FULLSCREEN", 0); - d->winActionCloseAtom = + atoms.winActionClose = XInternAtom (dpy, "_NET_WM_ACTION_CLOSE", 0); - d->winActionShadeAtom = + atoms.winActionShade = XInternAtom (dpy, "_NET_WM_ACTION_SHADE", 0); - d->winActionChangeDesktopAtom = + atoms.winActionChangeDesktop = XInternAtom (dpy, "_NET_WM_ACTION_CHANGE_DESKTOP", 0); - d->winActionAboveAtom = + atoms.winActionAbove = XInternAtom (dpy, "_NET_WM_ACTION_ABOVE", 0); - d->winActionBelowAtom = + atoms.winActionBelow = XInternAtom (dpy, "_NET_WM_ACTION_BELOW", 0); - d->wmAllowedActionsAtom = XInternAtom (dpy, "_NET_WM_ALLOWED_ACTIONS", 0); + atoms.wmAllowedActions = XInternAtom (dpy, "_NET_WM_ALLOWED_ACTIONS", 0); - d->wmStrutAtom = XInternAtom (dpy, "_NET_WM_STRUT", 0); - d->wmStrutPartialAtom = XInternAtom (dpy, "_NET_WM_STRUT_PARTIAL", 0); + atoms.wmStrut = XInternAtom (dpy, "_NET_WM_STRUT", 0); + atoms.wmStrutPartial = XInternAtom (dpy, "_NET_WM_STRUT_PARTIAL", 0); - d->wmUserTimeAtom = XInternAtom (dpy, "_NET_WM_USER_TIME", 0); + atoms.wmUserTime = XInternAtom (dpy, "_NET_WM_USER_TIME", 0); - d->wmIconAtom = XInternAtom (dpy,"_NET_WM_ICON", 0); - d->wmIconGeometryAtom = XInternAtom (dpy, "_NET_WM_ICON_GEOMETRY", 0); + atoms.wmIcon = XInternAtom (dpy,"_NET_WM_ICON", 0); + atoms.wmIconGeometry = XInternAtom (dpy, "_NET_WM_ICON_GEOMETRY", 0); - d->clientListAtom = XInternAtom (dpy, "_NET_CLIENT_LIST", 0); - d->clientListStackingAtom = + atoms.clientList = XInternAtom (dpy, "_NET_CLIENT_LIST", 0); + atoms.clientListStacking = XInternAtom (dpy, "_NET_CLIENT_LIST_STACKING", 0); - d->frameExtentsAtom = XInternAtom (dpy, "_NET_FRAME_EXTENTS", 0); - d->frameWindowAtom = XInternAtom (dpy, "_NET_FRAME_WINDOW", 0); + atoms.frameExtents = XInternAtom (dpy, "_NET_FRAME_EXTENTS", 0); + atoms.frameWindow = XInternAtom (dpy, "_NET_FRAME_WINDOW", 0); - d->wmStateAtom = XInternAtom (dpy, "WM_STATE", 0); - d->wmChangeStateAtom = XInternAtom (dpy, "WM_CHANGE_STATE", 0); - d->wmProtocolsAtom = XInternAtom (dpy, "WM_PROTOCOLS", 0); - d->wmClientLeaderAtom = XInternAtom (dpy, "WM_CLIENT_LEADER", 0); + atoms.wmState = XInternAtom (dpy, "WM_STATE", 0); + atoms.wmChangeState = XInternAtom (dpy, "WM_CHANGE_STATE", 0); + atoms.wmProtocols = XInternAtom (dpy, "WM_PROTOCOLS", 0); + atoms.wmClientLeader = XInternAtom (dpy, "WM_CLIENT_LEADER", 0); - d->wmDeleteWindowAtom = XInternAtom (dpy, "WM_DELETE_WINDOW", 0); - d->wmTakeFocusAtom = XInternAtom (dpy, "WM_TAKE_FOCUS", 0); - d->wmPingAtom = XInternAtom (dpy, "_NET_WM_PING", 0); - d->wmSyncRequestAtom = XInternAtom (dpy, "_NET_WM_SYNC_REQUEST", 0); + atoms.wmDeleteWindow = XInternAtom (dpy, "WM_DELETE_WINDOW", 0); + atoms.wmTakeFocus = XInternAtom (dpy, "WM_TAKE_FOCUS", 0); + atoms.wmPing = XInternAtom (dpy, "_NET_WM_PING", 0); + atoms.wmSyncRequest = XInternAtom (dpy, "_NET_WM_SYNC_REQUEST", 0); - d->wmSyncRequestCounterAtom = + atoms.wmSyncRequestCounter = XInternAtom (dpy, "_NET_WM_SYNC_REQUEST_COUNTER", 0); - d->closeWindowAtom = XInternAtom (dpy, "_NET_CLOSE_WINDOW", 0); - d->wmMoveResizeAtom = XInternAtom (dpy, "_NET_WM_MOVERESIZE", 0); - d->moveResizeWindowAtom = XInternAtom (dpy, "_NET_MOVERESIZE_WINDOW", 0); - d->restackWindowAtom = XInternAtom (dpy, "_NET_RESTACK_WINDOW", 0); + atoms.closeWindow = XInternAtom (dpy, "_NET_CLOSE_WINDOW", 0); + atoms.wmMoveResize = XInternAtom (dpy, "_NET_WM_MOVERESIZE", 0); + atoms.moveResizeWindow = XInternAtom (dpy, "_NET_MOVERESIZE_WINDOW", 0); + atoms.restackWindow = XInternAtom (dpy, "_NET_RESTACK_WINDOW", 0); - d->showingDesktopAtom = XInternAtom (dpy, "_NET_SHOWING_DESKTOP", 0); + atoms.showingDesktop = XInternAtom (dpy, "_NET_SHOWING_DESKTOP", 0); - d->xBackgroundAtom[0] = XInternAtom (dpy, "_XSETROOT_ID", 0); - d->xBackgroundAtom[1] = XInternAtom (dpy, "_XROOTPMAP_ID", 0); + atoms.xBackground[0] = XInternAtom (dpy, "_XSETROOT_ID", 0); + atoms.xBackground[1] = XInternAtom (dpy, "_XROOTPMAP_ID", 0); - d->toolkitActionAtom = + atoms.toolkitAction = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION", 0); - d->toolkitActionMainMenuAtom = + atoms.toolkitActionMainMenu = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION_MAIN_MENU", 0); - d->toolkitActionRunDialogAtom = + atoms.toolkitActionRunDialog = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION_RUN_DIALOG", 0); - d->toolkitActionWindowMenuAtom = + atoms.toolkitActionWindowMenu = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION_WINDOW_MENU", 0); - d->toolkitActionForceQuitDialogAtom = + atoms.toolkitActionForceQuitDialog = XInternAtom (dpy, "_COMPIZ_TOOLKIT_ACTION_FORCE_QUIT_DIALOG", 0); - d->mwmHintsAtom = XInternAtom (dpy, "_MOTIF_WM_HINTS", 0); - - d->xdndAwareAtom = XInternAtom (dpy, "XdndAware", 0); - d->xdndEnterAtom = XInternAtom (dpy, "XdndEnter", 0); - d->xdndLeaveAtom = XInternAtom (dpy, "XdndLeave", 0); - d->xdndPositionAtom = XInternAtom (dpy, "XdndPosition", 0); - d->xdndStatusAtom = XInternAtom (dpy, "XdndStatus", 0); - d->xdndDropAtom = XInternAtom (dpy, "XdndDrop", 0); - - d->managerAtom = XInternAtom (dpy, "MANAGER", 0); - d->targetsAtom = XInternAtom (dpy, "TARGETS", 0); - d->multipleAtom = XInternAtom (dpy, "MULTIPLE", 0); - d->timestampAtom = XInternAtom (dpy, "TIMESTAMP", 0); - d->versionAtom = XInternAtom (dpy, "VERSION", 0); - d->atomPairAtom = XInternAtom (dpy, "ATOM_PAIR", 0); + atoms.mwmHints = XInternAtom (dpy, "_MOTIF_WM_HINTS", 0); - d->startupIdAtom = XInternAtom (dpy, "_NET_STARTUP_ID", 0); + atoms.xdndAware = XInternAtom (dpy, "XdndAware", 0); + atoms.xdndEnter = XInternAtom (dpy, "XdndEnter", 0); + atoms.xdndLeave = XInternAtom (dpy, "XdndLeave", 0); + atoms.xdndPosition = XInternAtom (dpy, "XdndPosition", 0); + atoms.xdndStatus = XInternAtom (dpy, "XdndStatus", 0); + atoms.xdndDrop = XInternAtom (dpy, "XdndDrop", 0); - d->snDisplay = sn_display_new (dpy, NULL, NULL); - if (!d->snDisplay) - return FALSE; + atoms.manager = XInternAtom (dpy, "MANAGER", 0); + atoms.targets = XInternAtom (dpy, "TARGETS", 0); + atoms.multiple = XInternAtom (dpy, "MULTIPLE", 0); + atoms.timestamp = XInternAtom (dpy, "TIMESTAMP", 0); + atoms.version = XInternAtom (dpy, "VERSION", 0); + atoms.atomPair = XInternAtom (dpy, "ATOM_PAIR", 0); - d->lastPing = 1; + atoms.startupId = XInternAtom (dpy, "_NET_STARTUP_ID", 0); +} - if (!XQueryExtension (dpy, - COMPOSITE_NAME, - &d->compositeOpcode, - &d->compositeEvent, - &d->compositeError)) - { - compLogMessage (d, "core", CompLogLevelFatal, - "No composite extension"); - return FALSE; - } +bool +CompDisplay::fileToImage (const char *path, + const char *name, + int *width, + int *height, + int *stride, + void **data) +{ + WRAPABLE_HND_FUNC_RETURN(bool, fileToImage, path, name, width, height, + stride, data) + return false; +} - XCompositeQueryVersion (dpy, &compositeMajor, &compositeMinor); - if (compositeMajor == 0 && compositeMinor < 2) - { - compLogMessage (d, "core", CompLogLevelFatal, - "Old composite extension"); - return FALSE; - } +bool +CompDisplay::imageToFile (const char *path, + const char *name, + const char *format, + int width, + int height, + int stride, + void *data) +{ + WRAPABLE_HND_FUNC_RETURN(bool, imageToFile, path, name, format, width, + height, stride, data) + return false; +} - if (!XDamageQueryExtension (dpy, &d->damageEvent, &d->damageError)) - { - compLogMessage (d, "core", CompLogLevelFatal, - "No damage extension"); - return FALSE; +void +CompDisplay::logMessage (const char *componentName, + CompLogLevel level, + const char *message) +{ + WRAPABLE_HND_FUNC(logMessage, componentName, level, message) + compLogMessage (NULL, componentName, level, message); +} + +const char * +logLevelToString (CompLogLevel level) +{ + switch (level) { + case CompLogLevelFatal: + return "Fatal"; + case CompLogLevelError: + return "Error"; + case CompLogLevelWarn: + return "Warn"; + case CompLogLevelInfo: + return "Info"; + case CompLogLevelDebug: + return "Debug"; + default: + break; } - if (!XSyncQueryExtension (dpy, &d->syncEvent, &d->syncError)) - { - compLogMessage (d, "core", CompLogLevelFatal, - "No sync extension"); - return FALSE; - } + return "Unknown"; +} - if (!XFixesQueryExtension (dpy, &d->fixesEvent, &d->fixesError)) - { - compLogMessage (d, "core", CompLogLevelFatal, - "No fixes extension"); - return FALSE; - } +static void +logMessage (const char *componentName, + CompLogLevel level, + const char *message) +{ + fprintf (stderr, "%s (%s) - %s: %s\n", + programName, componentName, + logLevelToString (level), message); +} - XFixesQueryVersion (dpy, &d->fixesVersion, &fixesMinor); - /* - if (d->fixesVersion < 5) - { - fprintf (stderr, "%s: Need fixes extension version 5 or later " - "for client-side cursor\n", programName); - } - */ +void +compLogMessage (CompDisplay *d, + const char *componentName, + CompLogLevel level, + const char *format, + ...) +{ + va_list args; + char message[2048]; - d->randrExtension = XRRQueryExtension (dpy, - &d->randrEvent, - &d->randrError); + va_start (args, format); - d->shapeExtension = XShapeQueryExtension (dpy, - &d->shapeEvent, - &d->shapeError); + vsnprintf (message, 2048, format, args); - d->xkbExtension = XkbQueryExtension (dpy, - &xkbOpcode, - &d->xkbEvent, - &d->xkbError, - NULL, NULL); - if (d->xkbExtension) - { - XkbSelectEvents (dpy, - XkbUseCoreKbd, - XkbBellNotifyMask | XkbStateNotifyMask, - XkbAllEventsMask); - } + if (d) + d->logMessage (componentName, level, message); else - { - compLogMessage (d, "core", CompLogLevelFatal, - "No XKB extension"); - - d->xkbEvent = d->xkbError = -1; - } - - d->screenInfo = NULL; - d->nScreenInfo = 0; - - d->xineramaExtension = XineramaQueryExtension (dpy, - &d->xineramaEvent, - &d->xineramaError); + logMessage (componentName, level, message); - if (d->xineramaExtension) - d->screenInfo = XineramaQueryScreens (dpy, &d->nScreenInfo); - - d->escapeKeyCode = XKeysymToKeycode (dpy, XStringToKeysym ("Escape")); - d->returnKeyCode = XKeysymToKeycode (dpy, XStringToKeysym ("Return")); - - addDisplayToCore (d); + va_end (args); +} - /* TODO: bailout properly when objectInitPlugins fails */ - assert (objectInitPlugins (&d->base)); +int +CompDisplay::getWmState (Window id) +{ + Atom actual; + int result, format; + unsigned long n, left; + unsigned char *data; + unsigned long state = NormalState; - (*core.objectAdd) (&core.base, &d->base); + result = XGetWindowProperty (priv->dpy, id, + priv->atoms.wmState, 0L, 2L, FALSE, + priv->atoms.wmState, &actual, &format, + &n, &left, &data); - if (onlyCurrentScreen) - { - firstScreen = DefaultScreen (dpy); - lastScreen = DefaultScreen (dpy); - } - else + if (result == Success && n && data) { - firstScreen = 0; - lastScreen = ScreenCount (dpy) - 1; + memcpy (&state, data, sizeof (unsigned long)); + XFree ((void *) data); } - for (i = firstScreen; i <= lastScreen; i++) - { - Window newWmSnOwner = None, newCmSnOwner = None; - Atom wmSnAtom = 0, cmSnAtom = 0; - Time wmSnTimestamp = 0; - XEvent event; - XSetWindowAttributes attr; - Window currentWmSnOwner, currentCmSnOwner; - char buf[128]; - Window rootDummy, childDummy; - unsigned int uDummy; - int x, y, dummy; - - sprintf (buf, "WM_S%d", i); - wmSnAtom = XInternAtom (dpy, buf, 0); - - currentWmSnOwner = XGetSelectionOwner (dpy, wmSnAtom); - - if (currentWmSnOwner != None) - { - if (!replaceCurrentWm) - { - compLogMessage (d, "core", CompLogLevelError, - "Screen %d on display \"%s\" already " - "has a window manager; try using the " - "--replace option to replace the current " - "window manager.", - i, DisplayString (dpy)); - - continue; - } - - XSelectInput (dpy, currentWmSnOwner, - StructureNotifyMask); - } - - sprintf (buf, "_NET_WM_CM_S%d", i); - cmSnAtom = XInternAtom (dpy, buf, 0); - - currentCmSnOwner = XGetSelectionOwner (dpy, cmSnAtom); - - if (currentCmSnOwner != None) - { - if (!replaceCurrentWm) - { - compLogMessage (d, "core", CompLogLevelError, - "Screen %d on display \"%s\" already " - "has a compositing manager; try using the " - "--replace option to replace the current " - "compositing manager.", - i, DisplayString (dpy)); - - continue; - } - } - - attr.override_redirect = TRUE; - attr.event_mask = PropertyChangeMask; - - newCmSnOwner = newWmSnOwner = - XCreateWindow (dpy, XRootWindow (dpy, i), - -100, -100, 1, 1, 0, - CopyFromParent, CopyFromParent, - CopyFromParent, - CWOverrideRedirect | CWEventMask, - &attr); - - XChangeProperty (dpy, - newWmSnOwner, - d->wmNameAtom, - d->utf8StringAtom, 8, - PropModeReplace, - (unsigned char *) PACKAGE, - strlen (PACKAGE)); - - XWindowEvent (dpy, - newWmSnOwner, - PropertyChangeMask, - &event); - - wmSnTimestamp = event.xproperty.time; - - XSetSelectionOwner (dpy, wmSnAtom, newWmSnOwner, wmSnTimestamp); - - if (XGetSelectionOwner (dpy, wmSnAtom) != newWmSnOwner) - { - compLogMessage (d, "core", CompLogLevelError, - "Could not acquire window manager " - "selection on screen %d display \"%s\"", - i, DisplayString (dpy)); - - XDestroyWindow (dpy, newWmSnOwner); - - continue; - } - - /* Send client message indicating that we are now the WM */ - event.xclient.type = ClientMessage; - event.xclient.window = XRootWindow (dpy, i); - event.xclient.message_type = d->managerAtom; - event.xclient.format = 32; - event.xclient.data.l[0] = wmSnTimestamp; - event.xclient.data.l[1] = wmSnAtom; - event.xclient.data.l[2] = 0; - event.xclient.data.l[3] = 0; - event.xclient.data.l[4] = 0; - - XSendEvent (dpy, XRootWindow (dpy, i), FALSE, - StructureNotifyMask, &event); - - /* Wait for old window manager to go away */ - if (currentWmSnOwner != None) - { - do { - XWindowEvent (dpy, currentWmSnOwner, - StructureNotifyMask, &event); - } while (event.type != DestroyNotify); - } - - compCheckForError (dpy); - - XCompositeRedirectSubwindows (dpy, XRootWindow (dpy, i), - CompositeRedirectManual); - - if (compCheckForError (dpy)) - { - compLogMessage (d, "core", CompLogLevelError, - "Another composite manager is already " - "running on screen: %d", i); + return state; +} - continue; - } +void +CompDisplay::setWmState (int state, Window id) +{ + unsigned long data[2]; - XSetSelectionOwner (dpy, cmSnAtom, newCmSnOwner, wmSnTimestamp); + data[0] = state; + data[1] = None; - if (XGetSelectionOwner (dpy, cmSnAtom) != newCmSnOwner) - { - compLogMessage (d, "core", CompLogLevelError, - "Could not acquire compositing manager " - "selection on screen %d display \"%s\"", - i, DisplayString (dpy)); + XChangeProperty (priv->dpy, id, + priv->atoms.wmState, priv->atoms.wmState, + 32, PropModeReplace, (unsigned char *) data, 2); +} - continue; - } +unsigned int +CompDisplay::windowStateMask (Atom state) +{ + if (state == priv->atoms.winStateModal) + return CompWindowStateModalMask; + else if (state == priv->atoms.winStateSticky) + return CompWindowStateStickyMask; + else if (state == priv->atoms.winStateMaximizedVert) + return CompWindowStateMaximizedVertMask; + else if (state == priv->atoms.winStateMaximizedHorz) + return CompWindowStateMaximizedHorzMask; + else if (state == priv->atoms.winStateShaded) + return CompWindowStateShadedMask; + else if (state == priv->atoms.winStateSkipTaskbar) + return CompWindowStateSkipTaskbarMask; + else if (state == priv->atoms.winStateSkipPager) + return CompWindowStateSkipPagerMask; + else if (state == priv->atoms.winStateHidden) + return CompWindowStateHiddenMask; + else if (state == priv->atoms.winStateFullscreen) + return CompWindowStateFullscreenMask; + else if (state == priv->atoms.winStateAbove) + return CompWindowStateAboveMask; + else if (state == priv->atoms.winStateBelow) + return CompWindowStateBelowMask; + else if (state == priv->atoms.winStateDemandsAttention) + return CompWindowStateDemandsAttentionMask; + else if (state == priv->atoms.winStateDisplayModal) + return CompWindowStateDisplayModalMask; - XGrabServer (dpy); - - XSelectInput (dpy, XRootWindow (dpy, i), - SubstructureRedirectMask | - SubstructureNotifyMask | - StructureNotifyMask | - PropertyChangeMask | - LeaveWindowMask | - EnterWindowMask | - KeyPressMask | - KeyReleaseMask | - ButtonPressMask | - ButtonReleaseMask | - FocusChangeMask | - ExposureMask); - - if (compCheckForError (dpy)) - { - compLogMessage (d, "core", CompLogLevelError, - "Another window manager is " - "already running on screen: %d", i); + return 0; +} - XUngrabServer (dpy); - continue; - } +unsigned int +CompDisplay::windowStateFromString (const char *str) +{ + if (strcasecmp (str, "modal") == 0) + return CompWindowStateModalMask; + else if (strcasecmp (str, "sticky") == 0) + return CompWindowStateStickyMask; + else if (strcasecmp (str, "maxvert") == 0) + return CompWindowStateMaximizedVertMask; + else if (strcasecmp (str, "maxhorz") == 0) + return CompWindowStateMaximizedHorzMask; + else if (strcasecmp (str, "shaded") == 0) + return CompWindowStateShadedMask; + else if (strcasecmp (str, "skiptaskbar") == 0) + return CompWindowStateSkipTaskbarMask; + else if (strcasecmp (str, "skippager") == 0) + return CompWindowStateSkipPagerMask; + else if (strcasecmp (str, "hidden") == 0) + return CompWindowStateHiddenMask; + else if (strcasecmp (str, "fullscreen") == 0) + return CompWindowStateFullscreenMask; + else if (strcasecmp (str, "above") == 0) + return CompWindowStateAboveMask; + else if (strcasecmp (str, "below") == 0) + return CompWindowStateBelowMask; + else if (strcasecmp (str, "demandsattention") == 0) + return CompWindowStateDemandsAttentionMask; - if (!addScreen (d, i, newWmSnOwner, wmSnAtom, wmSnTimestamp)) - { - compLogMessage (d, "core", CompLogLevelError, - "Failed to manage screen: %d", i); - } + return 0; +} - if (XQueryPointer (dpy, XRootWindow (dpy, i), - &rootDummy, &childDummy, - &x, &y, &dummy, &dummy, &uDummy)) - { - lastPointerX = pointerX = x; - lastPointerY = pointerY = y; - } +unsigned int +CompDisplay::getWindowState (Window id) +{ + Atom actual; + int result, format; + unsigned long n, left; + unsigned char *data; + unsigned int state = 0; - XUngrabServer (dpy); - } + result = XGetWindowProperty (priv->dpy, id, + priv->atoms.winState, + 0L, 1024L, FALSE, XA_ATOM, &actual, &format, + &n, &left, &data); - if (!d->screens) + if (result == Success && data) { - compLogMessage (d, "core", CompLogLevelFatal, - "No manageable screens found on display %s", - XDisplayName (name)); - return FALSE; - } - - setAudibleBell (d, d->opt[COMP_DISPLAY_OPTION_AUDIBLE_BELL].value.b); - - XGetInputFocus (dpy, &focus, &revertTo); - - /* move input focus to root window so that we get a FocusIn event when - moving it to the default window */ - XSetInputFocus (dpy, d->screens->root, RevertToPointerRoot, CurrentTime); + Atom *a = (Atom *) data; - if (focus == None || focus == PointerRoot) - { - focusDefaultWindow (d->screens); - } - else - { - CompWindow *w; + while (n--) + state |= windowStateMask (*a++); - w = findWindowAtDisplay (d, focus); - if (w) - { - moveInputFocusToWindow (w); - } - else - focusDefaultWindow (d->screens); + XFree ((void *) data); } - d->pingHandle = - compAddTimeout (d->opt[COMP_DISPLAY_OPTION_PING_DELAY].value.i, - d->opt[COMP_DISPLAY_OPTION_PING_DELAY].value.i + 500, - pingTimeout, d); - - return TRUE; + return state; } void -removeDisplay (CompDisplay *d) -{ - CompDisplay *p; - - for (p = core.displays; p; p = p->next) - if (p->next == d) - break; - - if (p) - p->next = d->next; - else - core.displays = NULL; - - while (d->screens) - removeScreen (d->screens); - - (*core.objectRemove) (&core.base, &d->base); - - objectFiniPlugins (&d->base); - - compRemoveTimeout (d->pingHandle); - - if (d->snDisplay) - sn_display_unref (d->snDisplay); - - XSync (d->display, False); - XCloseDisplay (d->display); - - freeDisplay (d); +CompDisplay::setWindowState (unsigned int state, + Window id) +{ + Atom data[32]; + int i = 0; + + if (state & CompWindowStateModalMask) + data[i++] = priv->atoms.winStateModal; + if (state & CompWindowStateStickyMask) + data[i++] = priv->atoms.winStateSticky; + if (state & CompWindowStateMaximizedVertMask) + data[i++] = priv->atoms.winStateMaximizedVert; + if (state & CompWindowStateMaximizedHorzMask) + data[i++] = priv->atoms.winStateMaximizedHorz; + if (state & CompWindowStateShadedMask) + data[i++] = priv->atoms.winStateShaded; + if (state & CompWindowStateSkipTaskbarMask) + data[i++] = priv->atoms.winStateSkipTaskbar; + if (state & CompWindowStateSkipPagerMask) + data[i++] = priv->atoms.winStateSkipPager; + if (state & CompWindowStateHiddenMask) + data[i++] = priv->atoms.winStateHidden; + if (state & CompWindowStateFullscreenMask) + data[i++] = priv->atoms.winStateFullscreen; + if (state & CompWindowStateAboveMask) + data[i++] = priv->atoms.winStateAbove; + if (state & CompWindowStateBelowMask) + data[i++] = priv->atoms.winStateBelow; + if (state & CompWindowStateDemandsAttentionMask) + data[i++] = priv->atoms.winStateDemandsAttention; + if (state & CompWindowStateDisplayModalMask) + data[i++] = priv->atoms.winStateDisplayModal; + + XChangeProperty (priv->dpy, id, priv->atoms.winState, + XA_ATOM, 32, PropModeReplace, + (unsigned char *) data, i); } -Time -getCurrentTimeFromDisplay (CompDisplay *d) +unsigned int +CompDisplay::getWindowType (Window id) { - XEvent event; + Atom actual; + int result, format; + unsigned long n, left; + unsigned char *data; - XChangeProperty (d->display, d->screens->grabWindow, - XA_PRIMARY, XA_STRING, 8, - PropModeAppend, NULL, 0); - XWindowEvent (d->display, d->screens->grabWindow, - PropertyChangeMask, - &event); + result = XGetWindowProperty (priv->dpy , id, + priv->atoms.winType, + 0L, 1L, FALSE, XA_ATOM, &actual, &format, + &n, &left, &data); - return event.xproperty.time; -} - -CompScreen * -findScreenAtDisplay (CompDisplay *d, - Window root) -{ - CompScreen *s; - - for (s = d->screens; s; s = s->next) + if (result == Success && n && data) { - if (s->root == root) - return s; - } - - return 0; + Atom a; + + memcpy (&a, data, sizeof (Atom)); + XFree ((void *) data); + + if (a == priv->atoms.winTypeNormal) + return CompWindowTypeNormalMask; + else if (a == priv->atoms.winTypeMenu) + return CompWindowTypeMenuMask; + else if (a == priv->atoms.winTypeDesktop) + return CompWindowTypeDesktopMask; + else if (a == priv->atoms.winTypeDock) + return CompWindowTypeDockMask; + else if (a == priv->atoms.winTypeToolbar) + return CompWindowTypeToolbarMask; + else if (a == priv->atoms.winTypeUtil) + return CompWindowTypeUtilMask; + else if (a == priv->atoms.winTypeSplash) + return CompWindowTypeSplashMask; + else if (a == priv->atoms.winTypeDialog) + return CompWindowTypeDialogMask; + else if (a == priv->atoms.winTypeDropdownMenu) + return CompWindowTypeDropdownMenuMask; + else if (a == priv->atoms.winTypePopupMenu) + return CompWindowTypePopupMenuMask; + else if (a == priv->atoms.winTypeTooltip) + return CompWindowTypeTooltipMask; + else if (a == priv->atoms.winTypeNotification) + return CompWindowTypeNotificationMask; + else if (a == priv->atoms.winTypeCombo) + return CompWindowTypeComboMask; + else if (a == priv->atoms.winTypeDnd) + return CompWindowTypeDndMask; + } + + return CompWindowTypeUnknownMask; } void -forEachWindowOnDisplay (CompDisplay *display, - ForEachWindowProc proc, - void *closure) +CompDisplay::getMwmHints (Window id, + unsigned int *func, + unsigned int *decor) { - CompScreen *s; + Atom actual; + int result, format; + unsigned long n, left; + unsigned char *data; - for (s = display->screens; s; s = s->next) - forEachWindowOnScreen (s, proc, closure); -} + *func = MwmFuncAll; + *decor = MwmDecorAll; -CompWindow * -findWindowAtDisplay (CompDisplay *d, - Window id) -{ - CompScreen *s; - CompWindow *w; + result = XGetWindowProperty (priv->dpy, id, + priv->atoms.mwmHints, + 0L, 20L, FALSE, priv->atoms.mwmHints, + &actual, &format, &n, &left, &data); - for (s = d->screens; s; s = s->next) + if (result == Success && n && data) { - w = findWindowAtScreen (s, id); - if (w) - return w; - } + MwmHints *mwmHints = (MwmHints *) data; - return 0; -} + if (n >= PropMotifWmHintElements) + { + if (mwmHints->flags & MwmHintsDecorations) + *decor = mwmHints->decorations; -CompWindow * -findTopLevelWindowAtDisplay (CompDisplay *d, - Window id) -{ - CompScreen *s; - CompWindow *w; + if (mwmHints->flags & MwmHintsFunctions) + *func = mwmHints->functions; + } - for (s = d->screens; s; s = s->next) - { - w = findTopLevelWindowAtScreen (s, id); - if (w) - return w; + XFree (data); } - - return 0; } -static CompScreen * -findScreenForSelection (CompDisplay *display, - Window owner, - Atom selection) +unsigned int +CompDisplay::getProtocols (Window id) { - CompScreen *s; + Atom *protocol; + int count; + unsigned int protocols = 0; - for (s = display->screens; s; s = s->next) + if (XGetWMProtocols (priv->dpy, id, &protocol, &count)) { - if (s->wmSnSelectionWindow == owner && s->wmSnAtom == selection) - return s; - } + int i; - return NULL; -} - -/* from fvwm2, Copyright Matthias Clasen, Dominik Vogt */ -static Bool -convertProperty (CompDisplay *display, - CompScreen *screen, - Window w, - Atom target, - Atom property) -{ - -#define N_TARGETS 4 - - Atom conversionTargets[N_TARGETS]; - long icccmVersion[] = { 2, 0 }; - - conversionTargets[0] = display->targetsAtom; - conversionTargets[1] = display->multipleAtom; - conversionTargets[2] = display->timestampAtom; - conversionTargets[3] = display->versionAtom; - - if (target == display->targetsAtom) - XChangeProperty (display->display, w, property, - XA_ATOM, 32, PropModeReplace, - (unsigned char *) conversionTargets, N_TARGETS); - else if (target == display->timestampAtom) - XChangeProperty (display->display, w, property, - XA_INTEGER, 32, PropModeReplace, - (unsigned char *) &screen->wmSnTimestamp, 1); - else if (target == display->versionAtom) - XChangeProperty (display->display, w, property, - XA_INTEGER, 32, PropModeReplace, - (unsigned char *) icccmVersion, 2); - else - return FALSE; + for (i = 0; i < count; i++) + { + if (protocol[i] == priv->atoms.wmDeleteWindow) + protocols |= CompWindowProtocolDeleteMask; + else if (protocol[i] == priv->atoms.wmTakeFocus) + protocols |= CompWindowProtocolTakeFocusMask; + else if (protocol[i] == priv->atoms.wmPing) + protocols |= CompWindowProtocolPingMask; + else if (protocol[i] == priv->atoms.wmSyncRequest) + protocols |= CompWindowProtocolSyncRequestMask; + } - /* Be sure the PropertyNotify has arrived so we - * can send SelectionNotify - */ - XSync (display->display, FALSE); + XFree (protocol); + } - return TRUE; + return protocols; } -/* from fvwm2, Copyright Matthias Clasen, Dominik Vogt */ -void -handleSelectionRequest (CompDisplay *display, - XEvent *event) +unsigned int +CompDisplay::getWindowProp (Window id, + Atom property, + unsigned int defaultValue) { - XSelectionEvent reply; - CompScreen *screen; + Atom actual; + int result, format; + unsigned long n, left; + unsigned char *data; - screen = findScreenForSelection (display, - event->xselectionrequest.owner, - event->xselectionrequest.selection); - if (!screen) - return; + result = XGetWindowProperty (priv->dpy, id, property, + 0L, 1L, FALSE, XA_CARDINAL, &actual, &format, + &n, &left, &data); - reply.type = SelectionNotify; - reply.display = display->display; - reply.requestor = event->xselectionrequest.requestor; - reply.selection = event->xselectionrequest.selection; - reply.target = event->xselectionrequest.target; - reply.property = None; - reply.time = event->xselectionrequest.time; - - if (event->xselectionrequest.target == display->multipleAtom) + if (result == Success && n && data) { - if (event->xselectionrequest.property != None) - { - Atom type, *adata; - int i, format; - unsigned long num, rest; - unsigned char *data; - - if (XGetWindowProperty (display->display, - event->xselectionrequest.requestor, - event->xselectionrequest.property, - 0, 256, FALSE, - display->atomPairAtom, - &type, &format, &num, &rest, - &data) != Success) - return; + unsigned long value; - /* FIXME: to be 100% correct, should deal with rest > 0, - * but since we have 4 possible targets, we will hardly ever - * meet multiple requests with a length > 8 - */ - adata = (Atom *) data; - i = 0; - while (i < (int) num) - { - if (!convertProperty (display, screen, - event->xselectionrequest.requestor, - adata[i], adata[i + 1])) - adata[i + 1] = None; + memcpy (&value, data, sizeof (unsigned long)); - i += 2; - } - - XChangeProperty (display->display, - event->xselectionrequest.requestor, - event->xselectionrequest.property, - display->atomPairAtom, - 32, PropModeReplace, data, num); - } - } - else - { - if (event->xselectionrequest.property == None) - event->xselectionrequest.property = event->xselectionrequest.target; + XFree (data); - if (convertProperty (display, screen, - event->xselectionrequest.requestor, - event->xselectionrequest.target, - event->xselectionrequest.property)) - reply.property = event->xselectionrequest.property; + return (unsigned int) value; } - XSendEvent (display->display, - event->xselectionrequest.requestor, - FALSE, 0L, (XEvent *) &reply); + return defaultValue; } void -handleSelectionClear (CompDisplay *display, - XEvent *event) +CompDisplay::setWindowProp (Window id, + Atom property, + unsigned int value) { - /* We need to unmanage the screen on which we lost the selection */ - CompScreen *screen; + unsigned long data = value; - screen = findScreenForSelection (display, - event->xselectionclear.window, - event->xselectionclear.selection); - - if (screen) - shutDown = TRUE; + XChangeProperty (priv->dpy, id, property, + XA_CARDINAL, 32, PropModeReplace, + (unsigned char *) &data, 1); } -void -warpPointer (CompScreen *s, - int dx, - int dy) +bool +CompDisplay::readWindowProp32 (Window id, + Atom property, + unsigned short *returnValue) { - CompDisplay *display = s->display; - XEvent event; - - pointerX += dx; - pointerY += dy; + Atom actual; + int result, format; + unsigned long n, left; + unsigned char *data; - if (pointerX >= s->width) - pointerX = s->width - 1; - else if (pointerX < 0) - pointerX = 0; + result = XGetWindowProperty (priv->dpy, id, property, + 0L, 1L, FALSE, XA_CARDINAL, &actual, &format, + &n, &left, &data); - if (pointerY >= s->height) - pointerY = s->height - 1; - else if (pointerY < 0) - pointerY = 0; + if (result == Success && n && data) + { + CARD32 value; - XWarpPointer (display->display, - None, s->root, - 0, 0, 0, 0, - pointerX, pointerY); + memcpy (&value, data, sizeof (CARD32)); - XSync (display->display, FALSE); + XFree (data); - while (XCheckMaskEvent (display->display, - LeaveWindowMask | - EnterWindowMask | - PointerMotionMask, - &event)); + *returnValue = value >> 16; - if (!inHandleEvent) - { - lastPointerX = pointerX; - lastPointerY = pointerY; + return true; } + + return false; } -Bool -setDisplayAction (CompDisplay *display, - CompOption *o, - CompOptionValue *value) +unsigned short +CompDisplay::getWindowProp32 (Window id, + Atom property, + unsigned short defaultValue) { - CompScreen *s; - - for (s = display->screens; s; s = s->next) - if (!addScreenAction (s, &value->action)) - break; - - if (s) - { - CompScreen *failed = s; - - for (s = display->screens; s && s != failed; s = s->next) - removeScreenAction (s, &value->action); - - return FALSE; - } - else - { - for (s = display->screens; s; s = s->next) - removeScreenAction (s, &o->value.action); - } + unsigned short result; - if (compSetActionOption (o, value)) - return TRUE; + if (readWindowProp32 (id, property, &result)) + return result; - return FALSE; + return defaultValue; } void -clearTargetOutput (CompDisplay *display, - unsigned int mask) +CompDisplay::setWindowProp32 (Window id, + Atom property, + unsigned short value) { - if (targetScreen) - clearScreenOutput (targetScreen, - targetOutput, - mask); -} + CARD32 value32; -#define HOME_IMAGEDIR ".compiz/images" + value32 = value << 16 | value; -Bool -readImageFromFile (CompDisplay *display, - const char *name, - int *width, - int *height, - void **data) -{ - Bool status; - int stride; - - status = (*display->fileToImage) (display, NULL, name, width, height, - &stride, data); - if (!status) - { - char *home; - - home = getenv ("HOME"); - if (home) - { - char *path; - - path = (char *) malloc (strlen (home) + strlen (HOME_IMAGEDIR) + 2); - if (path) - { - sprintf (path, "%s/%s", home, HOME_IMAGEDIR); - status = (*display->fileToImage) (display, path, name, - width, height, &stride, - data); - - free (path); - - if (status) - return TRUE; - } - } - - status = (*display->fileToImage) (display, IMAGEDIR, name, - width, height, &stride, data); - } - - return status; + XChangeProperty (priv->dpy, id, property, + XA_CARDINAL, 32, PropModeReplace, + (unsigned char *) &value32, 1); } -Bool -writeImageToFile (CompDisplay *display, - const char *path, - const char *name, - const char *format, - int width, - int height, - void *data) -{ - return (*display->imageToFile) (display, path, name, format, width, height, - width * 4, data); -} -Bool -fileToImage (CompDisplay *display, - const char *path, - const char *name, - int *width, - int *height, - int *stride, - void **data) +DisplayInterface::DisplayInterface () { - return FALSE; + WRAPABLE_INIT_FUNC(handleEvent); + WRAPABLE_INIT_FUNC(handleCompizEvent); + WRAPABLE_INIT_FUNC(fileToImage); + WRAPABLE_INIT_FUNC(imageToFile); + WRAPABLE_INIT_FUNC(matchInitExp); + WRAPABLE_INIT_FUNC(matchExpHandlerChanged); + WRAPABLE_INIT_FUNC(matchPropertyChanged); + WRAPABLE_INIT_FUNC(logMessage); } -Bool -imageToFile (CompDisplay *display, - const char *path, - const char *name, - const char *format, - int width, - int height, - int stride, - void *data) -{ - return FALSE; -} +void +DisplayInterface::handleEvent (XEvent *event) + WRAPABLE_DEF_FUNC(handleEvent, event) -CompCursor * -findCursorAtDisplay (CompDisplay *display) -{ - CompScreen *s; +void +DisplayInterface::handleCompizEvent (const char *plugin, + const char *event, + CompOption *option, + int nOption) + WRAPABLE_DEF_FUNC(handleCompizEvent, plugin, event, option, nOption) + +bool +DisplayInterface::fileToImage (const char *path, + const char *name, + int *width, + int *height, + int *stride, + void **data) + WRAPABLE_DEF_FUNC_RETURN(fileToImage, path, name, width, height, + stride, data) + +bool +DisplayInterface::imageToFile (const char *path, + const char *name, + const char *format, + int width, + int height, + int stride, + void *data) + WRAPABLE_DEF_FUNC_RETURN(imageToFile, path, name, format, width, height, + stride, data) - for (s = display->screens; s; s = s->next) - if (s->cursors) - return s->cursors; +void +DisplayInterface::matchInitExp (CompMatchExp *exp, const char *value) + WRAPABLE_DEF_FUNC(matchInitExp, exp, value) - return NULL; +void +DisplayInterface::matchExpHandlerChanged () + WRAPABLE_DEF_FUNC(matchExpHandlerChanged) + +void +DisplayInterface::matchPropertyChanged (CompWindow *window) + WRAPABLE_DEF_FUNC(matchPropertyChanged, window) + +void +DisplayInterface::logMessage (const char *componentName, + CompLogLevel level, + const char *message) + WRAPABLE_DEF_FUNC(logMessage, componentName, level, message) + +PrivateDisplay::PrivateDisplay (CompDisplay *display) : + display (display), + screens (0), + watchFdHandle (0), + screenInfo (NULL), + nScreenInfo (0), + textureFilter (GL_LINEAR), + activeWindow (0), + below (None), + modMap (0), + ignoredModMask (LockMask), + autoRaiseHandle (0), + autoRaiseWindow (0), + edgeDelayHandle (0), + dirtyPluginList (true) +{ + for (int i = 0; i < CompModNum; i++) + modMask[i] = CompNoMask; + + compInitOptionValue (&plugin); +} + +PrivateDisplay::~PrivateDisplay () +{ } diff --git a/src/event.cpp b/src/event.cpp index ea4e781..9a97932 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -33,27 +33,30 @@ #include <X11/extensions/Xfixes.h> #include <compiz-core.h> +#include "privatedisplay.h" +#include "privatescreen.h" +#include "privatewindow.h" static Window xdndWindow = None; static Window edgeWindow = None; -static void -handleWindowDamageRect (CompWindow *w, - int x, - int y, - int width, - int height) +void +PrivateWindow::handleDamageRect (CompWindow *w, + int x, + int y, + int width, + int height) { REGION region; - Bool initial = FALSE; + bool initial = false; - if (!w->redirected || w->bindFailed) + if (!w->priv->redirected || w->priv->bindFailed) return; - if (!w->damaged) + if (!w->priv->damaged) { - w->damaged = initial = TRUE; - w->invisible = WINDOW_INVISIBLE (w); + w->priv->damaged = initial = true; + w->priv->invisible = WINDOW_INVISIBLE (w->priv); } region.extents.x1 = x; @@ -61,208 +64,150 @@ handleWindowDamageRect (CompWindow *w, region.extents.x2 = region.extents.x1 + width; region.extents.y2 = region.extents.y1 + height; - if (!(*w->screen->damageWindowRect) (w, initial, ®ion.extents)) + if (!w->damageRect (initial, ®ion.extents)) { - region.extents.x1 += w->attrib.x + w->attrib.border_width; - region.extents.y1 += w->attrib.y + w->attrib.border_width; - region.extents.x2 += w->attrib.x + w->attrib.border_width; - region.extents.y2 += w->attrib.y + w->attrib.border_width; + region.extents.x1 += w->priv->attrib.x + w->priv->attrib.border_width; + region.extents.y1 += w->priv->attrib.y + w->priv->attrib.border_width; + region.extents.x2 += w->priv->attrib.x + w->priv->attrib.border_width; + region.extents.y2 += w->priv->attrib.y + w->priv->attrib.border_width; region.rects = ®ion.extents; region.numRects = region.size = 1; - damageScreenRegion (w->screen, ®ion); + w->priv->screen->damageRegion (®ion); } if (initial) - damageWindowOutputExtents (w); + w->damageOutputExtents (); } -void -handleSyncAlarm (CompWindow *w) +bool +CompWindow::handleSyncAlarm () { - if (w->syncWait) + if (priv->syncWait) { - if (w->syncWaitHandle) + if (priv->syncWaitHandle) { - compRemoveTimeout (w->syncWaitHandle); - w->syncWaitHandle = 0; + core->removeTimeout (priv->syncWaitHandle); + priv->syncWaitHandle = 0; } - w->syncWait = FALSE; + priv->syncWait = FALSE; - if (resizeWindow (w, - w->syncX, w->syncY, - w->syncWidth, w->syncHeight, - w->syncBorderWidth)) + if (resize (priv->syncX, priv->syncY, + priv->syncWidth, priv->syncHeight, + priv->syncBorderWidth)) { XRectangle *rects; int nDamage; - nDamage = w->nDamage; - rects = w->damageRects; + nDamage = priv->nDamage; + rects = priv->damageRects; while (nDamage--) { - handleWindowDamageRect (w, - rects[nDamage].x, - rects[nDamage].y, - rects[nDamage].width, - rects[nDamage].height); + PrivateWindow::handleDamageRect (this, + rects[nDamage].x, + rects[nDamage].y, + rects[nDamage].width, + rects[nDamage].height); } - w->nDamage = 0; + priv->nDamage = 0; } else { /* resizeWindow failing means that there is another pending resize and we must send a new sync request to the client */ - sendSyncRequest (w); + sendSyncRequest (); } } -} - -static void -moveInputFocusToOtherWindow (CompWindow *w) -{ - CompDisplay *display = w->screen->display; - - if (w->id == display->activeWindow) - { - CompWindow *ancestor; - - if (w->transientFor && w->transientFor != w->screen->root) - { - ancestor = findWindowAtDisplay (display, w->transientFor); - if (ancestor && !(ancestor->type & (CompWindowTypeDesktopMask | - CompWindowTypeDockMask))) - { - moveInputFocusToWindow (ancestor); - } - else - focusDefaultWindow (w->screen); - } - else if (w->type & (CompWindowTypeDialogMask | - CompWindowTypeModalDialogMask)) - { - CompWindow *a, *focus = NULL; - for (a = w->screen->reverseWindows; a; a = a->prev) - { - if (a->clientLeader == w->clientLeader) - { - if ((*w->screen->focusWindow) (a)) - { - if (focus) - { - if (a->type & (CompWindowTypeNormalMask | - CompWindowTypeDialogMask | - CompWindowTypeModalDialogMask)) - { - if (compareWindowActiveness (focus, a) < 0) - focus = a; - } - } - else - focus = a; - } - } - } - - if (focus && !(focus->type & (CompWindowTypeDesktopMask | - CompWindowTypeDockMask))) - { - moveInputFocusToWindow (focus); - } - else - focusDefaultWindow (w->screen); - } - else - focusDefaultWindow (w->screen); - } + priv->syncWaitHandle = 0; + return false; } -static Bool + +static bool autoRaiseTimeout (void *closure) { CompDisplay *display = (CompDisplay *) closure; - CompWindow *w = findWindowAtDisplay (display, display->activeWindow); + CompWindow *w = display->findWindow (display->activeWindow ()); - if (display->autoRaiseWindow == display->activeWindow || - (w && (display->autoRaiseWindow == w->transientFor))) + if (display->autoRaiseWindow () == display->activeWindow () || + (w && (display->autoRaiseWindow () == w->transientFor ()))) { - w = findWindowAtDisplay (display, display->autoRaiseWindow); + w = display->findWindow (display->autoRaiseWindow ()); if (w) - updateWindowAttributes (w, CompStackingUpdateModeNormal); + w->updateAttributes (CompStackingUpdateModeNormal); } - return FALSE; + return false; } #define REAL_MOD_MASK (ShiftMask | ControlMask | Mod1Mask | Mod2Mask | \ Mod3Mask | Mod4Mask | Mod5Mask | CompNoMask) -static Bool +static bool isCallBackBinding (CompOption *option, CompBindingType type, CompActionState state) { if (!isActionOption (option)) - return FALSE; + return false; if (!(option->value.action.type & type)) - return FALSE; + return false; if (!(option->value.action.state & state)) - return FALSE; + return false; - return TRUE; + return true; } -static Bool +static bool isInitiateBinding (CompOption *option, CompBindingType type, CompActionState state, CompAction **action) { if (!isCallBackBinding (option, type, state)) - return FALSE; + return false; if (!option->value.action.initiate) - return FALSE; + return false; *action = &option->value.action; - return TRUE; + return true; } -static Bool +static bool isTerminateBinding (CompOption *option, CompBindingType type, CompActionState state, CompAction **action) { if (!isCallBackBinding (option, type, state)) - return FALSE; + return false; if (!option->value.action.terminate) - return FALSE; + return false; *action = &option->value.action; - return TRUE; + return true; } -static Bool -triggerButtonPressBindings (CompDisplay *d, - CompOption *option, - int nOption, - XEvent *event, - CompOption *argument, - int nArgument) +bool +PrivateDisplay::triggerButtonPressBindings (CompOption *option, + int nOption, + XEvent *event, + CompOption *argument, + int nArgument) { CompActionState state = CompActionStateInitButton; CompAction *action; - unsigned int modMask = REAL_MOD_MASK & ~d->ignoredModMask; + unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask; unsigned int bindMods; unsigned int edge = 0; @@ -271,22 +216,22 @@ triggerButtonPressBindings (CompDisplay *d, CompScreen *s; unsigned int i; - s = findScreenAtDisplay (d, event->xbutton.root); + s = display->findScreen (event->xbutton.root); if (!s) - return FALSE; + return false; if (event->xbutton.window != edgeWindow) { - if (!s->maxGrab || event->xbutton.window != s->root) - return FALSE; + if (!s->maxGrab () || event->xbutton.window != s->root ()) + return false; } for (i = 0; i < SCREEN_EDGE_NUM; i++) { - if (edgeWindow == s->screenEdge[i].id) + if (edgeWindow == s->screenEdge (i).id) { edge = 1 << i; - argument[1].value.i = d->activeWindow; + argument[1].value.i = display->activeWindow (); break; } } @@ -298,12 +243,13 @@ triggerButtonPressBindings (CompDisplay *d, { if (action->button.button == event->xbutton.button) { - bindMods = virtualToRealModMask (d, action->button.modifiers); + bindMods = + display->virtualToRealModMask (action->button.modifiers); if ((bindMods & modMask) == (event->xbutton.state & modMask)) - if ((*action->initiate) (d, action, state, + if ((*action->initiate) (display, action, state, argument, nArgument)) - return TRUE; + return true; } } @@ -315,15 +261,15 @@ triggerButtonPressBindings (CompDisplay *d, if ((action->button.button == event->xbutton.button) && (action->edgeMask & edge)) { - bindMods = virtualToRealModMask (d, - action->button.modifiers); + bindMods = + display->virtualToRealModMask (action->button.modifiers); if ((bindMods & modMask) == (event->xbutton.state & modMask)) - if ((*action->initiate) (d, action, state | + if ((*action->initiate) (display, action, state | CompActionStateInitEdge, argument, nArgument)) - return TRUE; + return true; } } } @@ -331,16 +277,15 @@ triggerButtonPressBindings (CompDisplay *d, option++; } - return FALSE; + return false; } -static Bool -triggerButtonReleaseBindings (CompDisplay *d, - CompOption *option, - int nOption, - XEvent *event, - CompOption *argument, - int nArgument) +bool +PrivateDisplay::triggerButtonReleaseBindings (CompOption *option, + int nOption, + XEvent *event, + CompOption *argument, + int nArgument) { CompActionState state = CompActionStateTermButton; CompBindingType type = CompBindingTypeButton | CompBindingTypeEdgeButton; @@ -352,34 +297,33 @@ triggerButtonReleaseBindings (CompDisplay *d, { if (action->button.button == event->xbutton.button) { - if ((*action->terminate) (d, action, state, + if ((*action->terminate) (display, action, state, argument, nArgument)) - return TRUE; + return true; } } option++; } - return FALSE; + return false; } -static Bool -triggerKeyPressBindings (CompDisplay *d, - CompOption *option, - int nOption, - XEvent *event, - CompOption *argument, - int nArgument) +bool +PrivateDisplay::triggerKeyPressBindings (CompOption *option, + int nOption, + XEvent *event, + CompOption *argument, + int nArgument) { CompActionState state = 0; CompAction *action; - unsigned int modMask = REAL_MOD_MASK & ~d->ignoredModMask; + unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask; unsigned int bindMods; - if (event->xkey.keycode == d->escapeKeyCode) + if (event->xkey.keycode == escapeKeyCode) state = CompActionStateCancel; - else if (event->xkey.keycode == d->returnKeyCode) + else if (event->xkey.keycode == returnKeyCode) state = CompActionStateCommit; if (state) @@ -392,7 +336,7 @@ triggerKeyPressBindings (CompDisplay *d, if (isActionOption (o)) { if (o->value.action.terminate) - (*o->value.action.terminate) (d, &o->value.action, + (*o->value.action.terminate) (display, &o->value.action, state, NULL, 0); } @@ -400,7 +344,7 @@ triggerKeyPressBindings (CompDisplay *d, } if (state == CompActionStateCancel) - return FALSE; + return false; } state = CompActionStateInitKey; @@ -408,61 +352,61 @@ triggerKeyPressBindings (CompDisplay *d, { if (isInitiateBinding (option, CompBindingTypeKey, state, &action)) { - bindMods = virtualToRealModMask (d, action->key.modifiers); + bindMods = display->virtualToRealModMask (action->key.modifiers); if (action->key.keycode == event->xkey.keycode) { if ((bindMods & modMask) == (event->xkey.state & modMask)) - if ((*action->initiate) (d, action, state, + if ((*action->initiate) (display, action, state, argument, nArgument)) - return TRUE; + return true; } - else if (!d->xkbEvent && action->key.keycode == 0) + else if (!xkbEvent && action->key.keycode == 0) { if (bindMods == (event->xkey.state & modMask)) - if ((*action->initiate) (d, action, state, + if ((*action->initiate) (display, action, state, argument, nArgument)) - return TRUE; + return true; } } option++; } - return FALSE; + return false; } -static Bool -triggerKeyReleaseBindings (CompDisplay *d, - CompOption *option, - int nOption, - XEvent *event, - CompOption *argument, - int nArgument) +bool +PrivateDisplay::triggerKeyReleaseBindings (CompOption *option, + int nOption, + XEvent *event, + CompOption *argument, + int nArgument) { - if (!d->xkbEvent) + if (!xkbEvent) { CompActionState state = CompActionStateTermKey; CompAction *action; - unsigned int modMask = REAL_MOD_MASK & ~d->ignoredModMask; + unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask; unsigned int bindMods; unsigned int mods; - mods = keycodeToModifiers (d, event->xkey.keycode); + mods = display->keycodeToModifiers (event->xkey.keycode); if (mods == 0) - return FALSE; + return false; while (nOption--) { if (isTerminateBinding (option, CompBindingTypeKey, state, &action)) { - bindMods = virtualToRealModMask (d, action->key.modifiers); + bindMods = + display->virtualToRealModMask (action->key.modifiers); if ((mods & modMask & bindMods) != bindMods) { - if ((*action->terminate) (d, action, state, + if ((*action->terminate) (display, action, state, argument, nArgument)) - return TRUE; + return true; } } @@ -470,20 +414,19 @@ triggerKeyReleaseBindings (CompDisplay *d, } } - return FALSE; + return false; } -static Bool -triggerStateNotifyBindings (CompDisplay *d, - CompOption *option, - int nOption, - XkbStateNotifyEvent *event, - CompOption *argument, - int nArgument) +bool +PrivateDisplay::triggerStateNotifyBindings (CompOption *option, + int nOption, + XkbStateNotifyEvent *event, + CompOption *argument, + int nArgument) { CompActionState state; CompAction *action; - unsigned int modMask = REAL_MOD_MASK & ~d->ignoredModMask; + unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask; unsigned int bindMods; if (event->event_type == KeyPress) @@ -496,13 +439,14 @@ triggerStateNotifyBindings (CompDisplay *d, { if (action->key.keycode == 0) { - bindMods = virtualToRealModMask (d, action->key.modifiers); + bindMods = + display->virtualToRealModMask (action->key.modifiers); if ((event->mods & modMask & bindMods) == bindMods) { - if ((*action->initiate) (d, action, state, + if ((*action->initiate) (display, action, state, argument, nArgument)) - return TRUE; + return true; } } } @@ -518,13 +462,14 @@ triggerStateNotifyBindings (CompDisplay *d, { if (isTerminateBinding (option, CompBindingTypeKey, state, &action)) { - bindMods = virtualToRealModMask (d, action->key.modifiers); + bindMods = + display->virtualToRealModMask (action->key.modifiers); if ((event->mods & modMask & bindMods) != bindMods) { - if ((*action->terminate) (d, action, state, + if ((*action->terminate) (display, action, state, argument, nArgument)) - return TRUE; + return true; } } @@ -532,33 +477,33 @@ triggerStateNotifyBindings (CompDisplay *d, } } - return FALSE; + return false; } -static Bool +static bool isBellAction (CompOption *option, CompActionState state, CompAction **action) { if (option->type != CompOptionTypeAction && option->type != CompOptionTypeBell) - return FALSE; + return false; if (!option->value.action.bell) - return FALSE; + return false; if (!(option->value.action.state & state)) - return FALSE; + return false; if (!option->value.action.initiate) - return FALSE; + return false; *action = &option->value.action; - return TRUE; + return true; } -static Bool +static bool triggerBellNotifyBindings (CompDisplay *d, CompOption *option, int nOption, @@ -573,16 +518,16 @@ triggerBellNotifyBindings (CompDisplay *d, if (isBellAction (option, state, &action)) { if ((*action->initiate) (d, action, state, argument, nArgument)) - return TRUE; + return true; } option++; } - return FALSE; + return false; } -static Bool +static bool isEdgeAction (CompOption *option, CompActionState state, unsigned int edge) @@ -590,18 +535,18 @@ isEdgeAction (CompOption *option, if (option->type != CompOptionTypeAction && option->type != CompOptionTypeButton && option->type != CompOptionTypeEdge) - return FALSE; + return false; if (!(option->value.action.edgeMask & edge)) - return FALSE; + return false; if (!(option->value.action.state & state)) - return FALSE; + return false; - return TRUE; + return true; } -static Bool +static bool isEdgeEnterAction (CompOption *option, CompActionState state, CompActionState delayState, @@ -609,13 +554,13 @@ isEdgeEnterAction (CompOption *option, CompAction **action) { if (!isEdgeAction (option, state, edge)) - return FALSE; + return false; if (option->value.action.type & CompBindingTypeEdgeButton) - return FALSE; + return false; if (!option->value.action.initiate) - return FALSE; + return false; if (delayState) { @@ -624,34 +569,34 @@ isEdgeEnterAction (CompOption *option, { /* ignore edge actions which shouldn't be delayed when invoking undelayed edges (or vice versa) */ - return FALSE; + return false; } } *action = &option->value.action; - return TRUE; + return true; } -static Bool +static bool isEdgeLeaveAction (CompOption *option, CompActionState state, unsigned int edge, CompAction **action) { if (!isEdgeAction (option, state, edge)) - return FALSE; + return false; if (!option->value.action.terminate) - return FALSE; + return false; *action = &option->value.action; - return TRUE; + return true; } -static Bool +static bool triggerEdgeEnterBindings (CompDisplay *d, CompOption *option, int nOption, @@ -668,16 +613,16 @@ triggerEdgeEnterBindings (CompDisplay *d, if (isEdgeEnterAction (option, state, delayState, edge, &action)) { if ((*action->initiate) (d, action, state, argument, nArgument)) - return TRUE; + return true; } option++; } - return FALSE; + return false; } -static Bool +static bool triggerEdgeLeaveBindings (CompDisplay *d, CompOption *option, int nOption, @@ -693,16 +638,16 @@ triggerEdgeLeaveBindings (CompDisplay *d, if (isEdgeLeaveAction (option, state, edge, &action)) { if ((*action->terminate) (d, action, state, argument, nArgument)) - return TRUE; + return true; } option++; } - return FALSE; + return false; } -static Bool +static bool triggerAllEdgeEnterBindings (CompDisplay *d, CompActionState state, CompActionState delayState, @@ -716,22 +661,19 @@ triggerAllEdgeEnterBindings (CompDisplay *d, for (p = getPlugins (); p; p = p->next) { - if (p->vTable->getObjectOptions) + option = p->vTable->getObjectOptions (d, &nOption); + if (triggerEdgeEnterBindings (d, + option, nOption, + state, delayState, edge, + argument, nArgument)) { - option = (*p->vTable->getObjectOptions) (p, &d->base, &nOption); - if (triggerEdgeEnterBindings (d, - option, nOption, - state, delayState, edge, - argument, nArgument)) - { - return TRUE; - } + return true; } } - return FALSE; + return false; } -static Bool +static bool delayedEdgeTimeout (void *closure) { CompDelayedEdgeSettings *settings = (CompDelayedEdgeSettings *) closure; @@ -745,30 +687,30 @@ delayedEdgeTimeout (void *closure) free (settings); - return FALSE; + return false; } -static Bool -triggerEdgeEnter (CompDisplay *d, - unsigned int edge, - CompActionState state, - CompOption *argument, - unsigned int nArgument) +bool +PrivateDisplay::triggerEdgeEnter (unsigned int edge, + CompActionState state, + CompOption *argument, + unsigned int nArgument) { int delay; CompDelayedEdgeSettings *delayedSettings = NULL; - delay = d->opt[COMP_DISPLAY_OPTION_EDGE_DELAY].value.i; + delay = opt[COMP_DISPLAY_OPTION_EDGE_DELAY].value.i; if (nArgument > 7) nArgument = 7; if (delay > 0) { - delayedSettings = (CompDelayedEdgeSettings *) malloc (sizeof (CompDelayedEdgeSettings)); + delayedSettings = (CompDelayedEdgeSettings *) + malloc (sizeof (CompDelayedEdgeSettings)); if (delayedSettings) { - delayedSettings->d = d; + delayedSettings->d = display; delayedSettings->edge = edge; delayedSettings->state = state; delayedSettings->nOption = nArgument; @@ -783,30 +725,29 @@ triggerEdgeEnter (CompDisplay *d, for (i = 0; i < nArgument; i++) delayedSettings->option[i] = argument[i]; - d->edgeDelayHandle = compAddTimeout (delay, (float) delay * 1.2, - delayedEdgeTimeout, - delayedSettings); + edgeDelayHandle = core->addTimeout (delay, (float) delay * 1.2, + delayedEdgeTimeout, + delayedSettings); delayState = CompActionStateNoEdgeDelay; - if (triggerAllEdgeEnterBindings (d, state, delayState, + if (triggerAllEdgeEnterBindings (display, state, delayState, edge, argument, nArgument)) - return TRUE; + return true; } else { - if (triggerAllEdgeEnterBindings (d, state, 0, edge, + if (triggerAllEdgeEnterBindings (display, state, 0, edge, argument, nArgument)) - return TRUE; + return true; } - return FALSE; + return false; } -static Bool -handleActionEvent (CompDisplay *d, - XEvent *event) +bool +PrivateDisplay::handleActionEvent (XEvent *event) { - CompObject *obj = &d->base; + CompObject *obj = display; CompOption *option; int nOption; CompPlugin *p; @@ -849,12 +790,9 @@ handleActionEvent (CompDisplay *d, for (p = getPlugins (); p; p = p->next) { - if (!p->vTable->getObjectOptions) - continue; - - option = (*p->vTable->getObjectOptions) (p, obj, &nOption); - if (triggerButtonPressBindings (d, option, nOption, event, o, 8)) - return TRUE; + option = p->vTable->getObjectOptions (obj, &nOption); + if (triggerButtonPressBindings (option, nOption, event, o, 8)) + return true; } break; case ButtonRelease: @@ -875,17 +813,14 @@ handleActionEvent (CompDisplay *d, for (p = getPlugins (); p; p = p->next) { - if (!p->vTable->getObjectOptions) - continue; - - option = (*p->vTable->getObjectOptions) (p, obj, &nOption); - if (triggerButtonReleaseBindings (d, option, nOption, event, o, 8)) - return TRUE; + option = p->vTable->getObjectOptions (obj, &nOption); + if (triggerButtonReleaseBindings (option, nOption, event, o, 8)) + return true; } break; case KeyPress: o[0].value.i = event->xkey.window; - o[1].value.i = d->activeWindow; + o[1].value.i = activeWindow; o[2].value.i = event->xkey.state; o[3].value.i = event->xkey.x_root; o[4].value.i = event->xkey.y_root; @@ -901,17 +836,14 @@ handleActionEvent (CompDisplay *d, for (p = getPlugins (); p; p = p->next) { - if (!p->vTable->getObjectOptions) - continue; - - option = (*p->vTable->getObjectOptions) (p, obj, &nOption); - if (triggerKeyPressBindings (d, option, nOption, event, o, 8)) - return TRUE; + option = p->vTable->getObjectOptions (obj, &nOption); + if (triggerKeyPressBindings (option, nOption, event, o, 8)) + return true; } break; case KeyRelease: o[0].value.i = event->xkey.window; - o[1].value.i = d->activeWindow; + o[1].value.i = activeWindow; o[2].value.i = event->xkey.state; o[3].value.i = event->xkey.x_root; o[4].value.i = event->xkey.y_root; @@ -927,11 +859,9 @@ handleActionEvent (CompDisplay *d, for (p = getPlugins (); p; p = p->next) { - if (!p->vTable->getObjectOptions) - continue; - option = (*p->vTable->getObjectOptions) (p, obj, &nOption); - if (triggerKeyReleaseBindings (d, option, nOption, event, o, 8)) - return TRUE; + option = p->vTable->getObjectOptions (obj, &nOption); + if (triggerKeyReleaseBindings (option, nOption, event, o, 8)) + return true; } break; case EnterNotify: @@ -943,18 +873,18 @@ handleActionEvent (CompDisplay *d, unsigned int edge, i; CompActionState state; - s = findScreenAtDisplay (d, event->xcrossing.root); + s = display->findScreen (event->xcrossing.root); if (!s) - return FALSE; + return false; - if (d->edgeDelayHandle) + if (edgeDelayHandle) { void *closure; - closure = compRemoveTimeout (d->edgeDelayHandle); + closure = core->removeTimeout (edgeDelayHandle); if (closure) free (closure); - d->edgeDelayHandle = 0; + edgeDelayHandle = 0; } if (edgeWindow && edgeWindow != event->xcrossing.window) @@ -964,7 +894,7 @@ handleActionEvent (CompDisplay *d, for (i = 0; i < SCREEN_EDGE_NUM; i++) { - if (edgeWindow == s->screenEdge[i].id) + if (edgeWindow == s->screenEdge (i).id) { edge = 1 << i; break; @@ -974,7 +904,7 @@ handleActionEvent (CompDisplay *d, edgeWindow = None; o[0].value.i = event->xcrossing.window; - o[1].value.i = d->activeWindow; + o[1].value.i = activeWindow; o[2].value.i = event->xcrossing.state; o[3].value.i = event->xcrossing.x_root; o[4].value.i = event->xcrossing.y_root; @@ -986,13 +916,10 @@ handleActionEvent (CompDisplay *d, for (p = getPlugins (); p; p = p->next) { - if (!p->vTable->getObjectOptions) - continue; - - option = (*p->vTable->getObjectOptions) (p, obj, &nOption); - if (triggerEdgeLeaveBindings (d, option, nOption, state, - edge, o, 7)) - return TRUE; + option = p->vTable->getObjectOptions (obj, &nOption); + if (triggerEdgeLeaveBindings (display, option, nOption, + state, edge, o, 7)) + return true; } } @@ -1000,7 +927,7 @@ handleActionEvent (CompDisplay *d, for (i = 0; i < SCREEN_EDGE_NUM; i++) { - if (event->xcrossing.window == s->screenEdge[i].id) + if (event->xcrossing.window == s->screenEdge (i).id) { edge = 1 << i; break; @@ -1014,7 +941,7 @@ handleActionEvent (CompDisplay *d, edgeWindow = event->xcrossing.window; o[0].value.i = event->xcrossing.window; - o[1].value.i = d->activeWindow; + o[1].value.i = activeWindow; o[2].value.i = event->xcrossing.state; o[3].value.i = event->xcrossing.x_root; o[4].value.i = event->xcrossing.y_root; @@ -1024,17 +951,17 @@ handleActionEvent (CompDisplay *d, o[6].name = "time"; o[6].value.i = event->xcrossing.time; - if (triggerEdgeEnter (d, edge, state, o, 7)) - return TRUE; + if (triggerEdgeEnter (edge, state, o, 7)) + return true; } } break; case ClientMessage: - if (event->xclient.message_type == d->xdndEnterAtom) + if (event->xclient.message_type == atoms.xdndEnter) { xdndWindow = event->xclient.window; } - else if (event->xclient.message_type == d->xdndLeaveAtom) + else if (event->xclient.message_type == atoms.xdndLeave) { unsigned int edge = 0; CompActionState state; @@ -1044,18 +971,18 @@ handleActionEvent (CompDisplay *d, { CompWindow *w; - w = findWindowAtDisplay (d, event->xclient.window); + w = display->findWindow (event->xclient.window); if (w) { - CompScreen *s = w->screen; + CompScreen *s = w->screen (); unsigned int i; for (i = 0; i < SCREEN_EDGE_NUM; i++) { - if (event->xclient.window == s->screenEdge[i].id) + if (event->xclient.window == s->screenEdge (i).id) { edge = 1 << i; - root = s->root; + root = s->root (); break; } } @@ -1067,7 +994,7 @@ handleActionEvent (CompDisplay *d, state = CompActionStateTermEdgeDnd; o[0].value.i = event->xclient.window; - o[1].value.i = d->activeWindow; + o[1].value.i = activeWindow; o[2].value.i = 0; /* fixme */ o[3].value.i = 0; /* fixme */ o[4].value.i = 0; /* fixme */ @@ -1075,17 +1002,14 @@ handleActionEvent (CompDisplay *d, for (p = getPlugins (); p; p = p->next) { - if (!p->vTable->getObjectOptions) - continue; - - option = (*p->vTable->getObjectOptions) (p, obj, &nOption); - if (triggerEdgeLeaveBindings (d, option, nOption, state, - edge, o, 6)) - return TRUE; + option = p->vTable->getObjectOptions (obj, &nOption); + if (triggerEdgeLeaveBindings (display, option, nOption, + state, edge, o, 6)) + return true; } } } - else if (event->xclient.message_type == d->xdndPositionAtom) + else if (event->xclient.message_type == atoms.xdndPosition) { unsigned int edge = 0; CompActionState state; @@ -1095,18 +1019,18 @@ handleActionEvent (CompDisplay *d, { CompWindow *w; - w = findWindowAtDisplay (d, event->xclient.window); + w = display->findWindow (event->xclient.window); if (w) { - CompScreen *s = w->screen; + CompScreen *s = w->screen (); unsigned int i; for (i = 0; i < SCREEN_EDGE_NUM; i++) { - if (xdndWindow == s->screenEdge[i].id) + if (xdndWindow == s->screenEdge (i).id) { edge = 1 << i; - root = s->root; + root = s->root (); break; } } @@ -1118,21 +1042,21 @@ handleActionEvent (CompDisplay *d, state = CompActionStateInitEdgeDnd; o[0].value.i = event->xclient.window; - o[1].value.i = d->activeWindow; + o[1].value.i = activeWindow; o[2].value.i = 0; /* fixme */ o[3].value.i = event->xclient.data.l[2] >> 16; o[4].value.i = event->xclient.data.l[2] & 0xffff; o[5].value.i = root; - if (triggerEdgeEnter (d, edge, state, o, 6)) - return TRUE; + if (triggerEdgeEnter (edge, state, o, 6)) + return true; } xdndWindow = None; } break; default: - if (event->type == d->fixesEvent + XFixesCursorNotify) + if (event->type == fixesEvent + XFixesCursorNotify) { /* XFixesCursorNotifyEvent *ce = (XFixesCursorNotifyEvent *) event; @@ -1143,7 +1067,7 @@ handleActionEvent (CompDisplay *d, updateCursor (cursor, ce->x, ce->y, ce->cursor_serial); */ } - else if (event->type == d->xkbEvent) + else if (event->type == xkbEvent) { XkbAnyEvent *xkbEvent = (XkbAnyEvent *) event; @@ -1151,8 +1075,8 @@ handleActionEvent (CompDisplay *d, { XkbStateNotifyEvent *stateEvent = (XkbStateNotifyEvent *) event; - o[0].value.i = d->activeWindow; - o[1].value.i = d->activeWindow; + o[0].value.i = activeWindow; + o[1].value.i = activeWindow; o[2].value.i = stateEvent->mods; o[3].type = CompOptionTypeInt; @@ -1161,19 +1085,16 @@ handleActionEvent (CompDisplay *d, for (p = getPlugins (); p; p = p->next) { - if (!p->vTable->getObjectOptions) - continue; - - option = (*p->vTable->getObjectOptions) (p, obj, &nOption); - if (triggerStateNotifyBindings (d, option, nOption, + option = p->vTable->getObjectOptions (obj, &nOption); + if (triggerStateNotifyBindings (option, nOption, stateEvent, o, 4)) - return TRUE; + return true; } } else if (xkbEvent->xkb_type == XkbBellNotify) { - o[0].value.i = d->activeWindow; - o[1].value.i = d->activeWindow; + o[0].value.i = activeWindow; + o[1].value.i = activeWindow; o[2].type = CompOptionTypeInt; o[2].name = "time"; @@ -1181,535 +1102,477 @@ handleActionEvent (CompDisplay *d, for (p = getPlugins (); p; p = p->next) { - if (!p->vTable->getObjectOptions) - continue; - - option = (*p->vTable->getObjectOptions) (p, obj, &nOption); - if (triggerBellNotifyBindings (d, option, nOption, o, 3)) - return TRUE; + option = p->vTable->getObjectOptions (obj, &nOption); + if (triggerBellNotifyBindings (display, option, + nOption, o, 3)) + return true; } } } break; } - return FALSE; + return false; } void -handleCompizEvent (CompDisplay *d, - const char *pluginName, - const char *eventName, - CompOption *option, - int nOption) +CompScreen::handleExposeEvent (XExposeEvent *event) { + if (priv->output == event->window) + return; + + int more = event->count + 1; + + if (priv->nExpose == priv->sizeExpose) + { + priv->exposeRects = (XRectangle *) + realloc (priv->exposeRects, (priv->sizeExpose + more) * + sizeof (XRectangle)); + priv->sizeExpose += more; + } + + priv->exposeRects[priv->nExpose].x = event->x; + priv->exposeRects[priv->nExpose].y = event->y; + priv->exposeRects[priv->nExpose].width = event->width; + priv->exposeRects[priv->nExpose].height = event->height; + priv->nExpose++; + + if (event->count == 0) + { + REGION rect; + + rect.rects = &rect.extents; + rect.numRects = rect.size = 1; + + while (priv->nExpose--) + { + rect.extents.x1 = priv->exposeRects[priv->nExpose].x; + rect.extents.y1 = priv->exposeRects[priv->nExpose].y; + rect.extents.x2 = rect.extents.x1 + + priv->exposeRects[priv->nExpose].width; + rect.extents.y2 = rect.extents.y1 + + priv->exposeRects[priv->nExpose].height; + + damageRegion (&rect); + } + priv->nExpose = 0; + } } void -handleEvent (CompDisplay *d, - XEvent *event) +CompDisplay::handleCompizEvent (const char *plugin, + const char *event, + CompOption *option, + int nOption) + WRAPABLE_HND_FUNC(handleCompizEvent, plugin, event, option, nOption) + +void +CompDisplay::handleEvent (XEvent *event) { + WRAPABLE_HND_FUNC(handleEvent, event) + CompScreen *s; CompWindow *w; switch (event->type) { case ButtonPress: - s = findScreenAtDisplay (d, event->xbutton.root); + s = findScreen (event->xbutton.root); if (s) - setCurrentOutput (s, outputDeviceForPoint (s, - event->xbutton.x_root, - event->xbutton.y_root)); + s->setCurrentOutput ( + s->outputDeviceForPoint (event->xbutton.x_root, + event->xbutton.y_root)); break; case MotionNotify: - s = findScreenAtDisplay (d, event->xmotion.root); + s = findScreen (event->xmotion.root); if (s) - setCurrentOutput (s, outputDeviceForPoint (s, - event->xmotion.x_root, - event->xmotion.y_root)); + s->setCurrentOutput ( + s->outputDeviceForPoint (event->xmotion.x_root, + event->xmotion.y_root)); break; case KeyPress: - w = findWindowAtDisplay (d, d->activeWindow); + w = findWindow (priv->activeWindow); if (w) - setCurrentOutput (w->screen, outputDeviceForWindow (w)); + w->screen ()->setCurrentOutput (w->outputDevice ()); default: break; } - if (handleActionEvent (d, event)) + if (priv->handleActionEvent (event)) { - if (!d->screens->maxGrab) - XAllowEvents (d->display, AsyncPointer, event->xbutton.time); + if (!priv->screens->maxGrab ()) + XAllowEvents (priv->dpy, AsyncPointer, event->xbutton.time); return; } switch (event->type) { case Expose: - for (s = d->screens; s; s = s->next) - if (s->output == event->xexpose.window) - break; - - if (s) - { - int more = event->xexpose.count + 1; - - if (s->nExpose == s->sizeExpose) - { - s->exposeRects = (XRectangle *) realloc (s->exposeRects, - (s->sizeExpose + more) * - sizeof (XRectangle)); - s->sizeExpose += more; - } - - s->exposeRects[s->nExpose].x = event->xexpose.x; - s->exposeRects[s->nExpose].y = event->xexpose.y; - s->exposeRects[s->nExpose].width = event->xexpose.width; - s->exposeRects[s->nExpose].height = event->xexpose.height; - s->nExpose++; - - if (event->xexpose.count == 0) - { - REGION rect; - - rect.rects = &rect.extents; - rect.numRects = rect.size = 1; - - while (s->nExpose--) - { - rect.extents.x1 = s->exposeRects[s->nExpose].x; - rect.extents.y1 = s->exposeRects[s->nExpose].y; - rect.extents.x2 = rect.extents.x1 + - s->exposeRects[s->nExpose].width; - rect.extents.y2 = rect.extents.y1 + - s->exposeRects[s->nExpose].height; - - damageScreenRegion (s, &rect); - } - s->nExpose = 0; - } - } + for (s = priv->screens; s; s = s->next) + s->handleExposeEvent (&event->xexpose); break; case SelectionRequest: - handleSelectionRequest (d, event); + priv->handleSelectionRequest (event); break; case SelectionClear: - handleSelectionClear (d, event); + priv->handleSelectionClear (event); break; case ConfigureNotify: - w = findWindowAtDisplay (d, event->xconfigure.window); + w = findWindow (event->xconfigure.window); if (w) { - configureWindow (w, &event->xconfigure); + w->configure (&event->xconfigure); } else { - s = findScreenAtDisplay (d, event->xconfigure.window); + s = findScreen (event->xconfigure.window); if (s) - configureScreen (s, &event->xconfigure); + s->configure (&event->xconfigure); } break; case CreateNotify: - s = findScreenAtDisplay (d, event->xcreatewindow.parent); + s = findScreen (event->xcreatewindow.parent); if (s) { /* The first time some client asks for the composite * overlay window, the X server creates it, which causes * an errorneous CreateNotify event. We catch it and * ignore it. */ - if (s->overlay != event->xcreatewindow.window) - addWindow (s, event->xcreatewindow.window, getTopWindow (s)); + if (s->overlay () != event->xcreatewindow.window) + new CompWindow (s, event->xcreatewindow.window, + s->getTopWindow ()); } break; case DestroyNotify: - w = findWindowAtDisplay (d, event->xdestroywindow.window); + w = findWindow (event->xdestroywindow.window); if (w) { - moveInputFocusToOtherWindow (w); - destroyWindow (w); + w->moveInputFocusToOtherWindow (); + w->destroy (); } break; case MapNotify: - w = findWindowAtDisplay (d, event->xmap.window); + w = findWindow (event->xmap.window); if (w) { - if (!w->attrib.override_redirect) - w->managed = TRUE; + if (!w->attrib ().override_redirect) + w->managed () = true; /* been shaded */ - if (w->height == 0) + if (w->height () == 0) { - if (w->id == d->activeWindow) - moveInputFocusToWindow (w); + if (w->id () == priv->activeWindow) + w->moveInputFocusTo (); } - mapWindow (w); + w->map (); } break; case UnmapNotify: - w = findWindowAtDisplay (d, event->xunmap.window); + w = findWindow (event->xunmap.window); if (w) { /* Normal -> Iconic */ - if (w->pendingUnmaps) + if (w->pendingUnmaps ()) { - setWmState (d, IconicState, w->id); - w->pendingUnmaps--; + setWmState (IconicState, w->id ()); + w->pendingUnmaps ()--; } else /* X -> Withdrawn */ { /* Iconic -> Withdrawn */ - if (w->state & CompWindowStateHiddenMask) + if (w->state () & CompWindowStateHiddenMask) { - w->minimized = FALSE; + w->minimized () = false; - changeWindowState (w, - w->state & ~CompWindowStateHiddenMask); + w->changeState (w->state () & ~CompWindowStateHiddenMask); - updateClientListForScreen (w->screen); + w->screen () ->updateClientList (); } - if (!w->attrib.override_redirect) - setWmState (d, WithdrawnState, w->id); + if (!w->attrib ().override_redirect) + setWmState (WithdrawnState, w->id ()); - w->placed = FALSE; - w->managed = FALSE; + w->placed () = false; + w->managed () = false; } - unmapWindow (w); + w->unmap (); - if (!w->shaded) - moveInputFocusToOtherWindow (w); + if (!w->shaded ()) + w->moveInputFocusToOtherWindow (); } break; case ReparentNotify: - w = findWindowAtDisplay (d, event->xreparent.window); - s = findScreenAtDisplay (d, event->xreparent.parent); + w = findWindow (event->xreparent.window); + s = findScreen (event->xreparent.parent); if (s && !w) { - addWindow (s, event->xreparent.window, getTopWindow (s)); + new CompWindow (s, event->xreparent.window, s->getTopWindow ()); } else if (w) { /* This is the only case where a window is removed but not destroyed. We must remove our event mask and all passive grabs. */ - XSelectInput (d->display, w->id, NoEventMask); - XShapeSelectInput (d->display, w->id, NoEventMask); - XUngrabButton (d->display, AnyButton, AnyModifier, w->id); + XSelectInput (priv->dpy, w->id (), NoEventMask); + XShapeSelectInput (priv->dpy, w->id (), NoEventMask); + XUngrabButton (priv->dpy, AnyButton, AnyModifier, w->id ()); - moveInputFocusToOtherWindow (w); + w->moveInputFocusToOtherWindow (); - destroyWindow (w); + w->destroy (); } break; case CirculateNotify: - w = findWindowAtDisplay (d, event->xcirculate.window); + w = findWindow (event->xcirculate.window); if (w) - circulateWindow (w, &event->xcirculate); + w->circulate (&event->xcirculate); break; case ButtonPress: - s = findScreenAtDisplay (d, event->xbutton.root); + s = findScreen (event->xbutton.root); if (s) { if (event->xbutton.button == Button1 || event->xbutton.button == Button2 || event->xbutton.button == Button3) { - w = findTopLevelWindowAtScreen (s, event->xbutton.window); + w = s->findTopLevelWindow (event->xbutton.window); if (w) { - if (d->opt[COMP_DISPLAY_OPTION_RAISE_ON_CLICK].value.b) - updateWindowAttributes (w, + if (priv->opt[COMP_DISPLAY_OPTION_RAISE_ON_CLICK].value.b) + w->updateAttributes ( CompStackingUpdateModeAboveFullscreen); - if (w->id != d->activeWindow) - if (!(w->type & CompWindowTypeDockMask)) - moveInputFocusToWindow (w); + if (w->id () != priv->activeWindow) + if (!(w->type () & CompWindowTypeDockMask)) + w->moveInputFocusTo (); } } - if (!s->maxGrab) - XAllowEvents (d->display, ReplayPointer, event->xbutton.time); + if (!s->maxGrab ()) + XAllowEvents (priv->dpy, ReplayPointer, event->xbutton.time); } break; case PropertyNotify: - if (event->xproperty.atom == d->winTypeAtom) + if (event->xproperty.atom == priv->atoms.winType) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) { unsigned int type; - type = getWindowType (d, w->id); + type = getWindowType (w->id ()); - if (type != w->wmType) + if (type != w->wmType ()) { - if (w->attrib.map_state == IsViewable) + if (w->attrib ().map_state == IsViewable) { - if (w->type == CompWindowTypeDesktopMask) - w->screen->desktopWindowCount--; + if (w->type () == CompWindowTypeDesktopMask) + w->screen ()->desktopWindowCount ()--; else if (type == CompWindowTypeDesktopMask) - w->screen->desktopWindowCount++; + w->screen ()->desktopWindowCount ()++; } - w->wmType = type; + w->wmType () = type; - recalcWindowType (w); - recalcWindowActions (w); - - if (w->type & CompWindowTypeDesktopMask) - w->paint.opacity = OPAQUE; + w->recalcType (); + w->recalcActions (); if (type & (CompWindowTypeDockMask | CompWindowTypeDesktopMask)) - setDesktopForWindow (w, 0xffffffff); + w->setDesktop (0xffffffff); - updateClientListForScreen (w->screen); + w->screen ()->updateClientList (); - (*d->matchPropertyChanged) (d, w); + matchPropertyChanged (w); } } } - else if (event->xproperty.atom == d->winStateAtom) + else if (event->xproperty.atom == priv->atoms.winState) { - w = findWindowAtDisplay (d, event->xproperty.window); - if (w && !w->managed) + w = findWindow (event->xproperty.window); + if (w && !w->managed ()) { unsigned int state; - state = getWindowState (d, w->id); - state = constrainWindowState (state, w->actions); + state = getWindowState (w->id ()); + state = CompWindow::constrainWindowState (state, w->actions ()); - if (state != w->state) + if (state != w->state ()) { - w->state = state; - - recalcWindowType (w); - recalcWindowActions (w); + w->state () = state; - if (w->type & CompWindowTypeDesktopMask) - w->paint.opacity = OPAQUE; + w->recalcType (); + w->recalcActions (); - (*d->matchPropertyChanged) (d, w); + matchPropertyChanged (w); } } } else if (event->xproperty.atom == XA_WM_NORMAL_HINTS) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) { - updateNormalHints (w); - recalcWindowActions (w); + w->updateNormalHints (); + w->recalcActions (); } } else if (event->xproperty.atom == XA_WM_HINTS) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) - updateWmHints (w); + w->updateWmHints (); } else if (event->xproperty.atom == XA_WM_TRANSIENT_FOR) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) { - updateTransientHint (w); - recalcWindowActions (w); + w->updateTransientHint (); + w->recalcActions (); } } - else if (event->xproperty.atom == d->wmClientLeaderAtom) + else if (event->xproperty.atom == priv->atoms.wmClientLeader) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) - w->clientLeader = getClientLeader (w); + w->clientLeader () = w->getClientLeader (); } - else if (event->xproperty.atom == d->wmIconGeometryAtom) + else if (event->xproperty.atom == priv->atoms.wmIconGeometry) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) - updateIconGeometry (w); + w->updateIconGeometry (); } - else if (event->xproperty.atom == d->winOpacityAtom) + else if (event->xproperty.atom == priv->atoms.winOpacity) { - w = findWindowAtDisplay (d, event->xproperty.window); - if (w && (w->type & CompWindowTypeDesktopMask) == 0) - { - w->opacity = OPAQUE; - w->opacityPropSet = - readWindowProp32 (d, w->id, d->winOpacityAtom, &w->opacity); - - updateWindowOpacity (w); - } + w = findWindow (event->xproperty.window); + if (w) + w->updateOpacity (); } - else if (event->xproperty.atom == d->winBrightnessAtom) + else if (event->xproperty.atom == priv->atoms.winBrightness) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) - { - GLushort brightness; - - brightness = getWindowProp32 (d, w->id, - d->winBrightnessAtom, - BRIGHT); - if (brightness != w->brightness) - { - w->brightness = brightness; - if (w->alive) - { - w->paint.brightness = w->brightness; - addWindowDamage (w); - } - } - } + w->updateBrightness (); } - else if (event->xproperty.atom == d->winSaturationAtom) + else if (event->xproperty.atom == priv->atoms.winSaturation) { - w = findWindowAtDisplay (d, event->xproperty.window); - if (w && w->screen->canDoSaturated) - { - GLushort saturation; - - saturation = getWindowProp32 (d, w->id, - d->winSaturationAtom, - COLOR); - if (saturation != w->saturation) - { - w->saturation = saturation; - if (w->alive) - { - w->paint.saturation = w->saturation; - addWindowDamage (w); - } - } - } + w = findWindow (event->xproperty.window); + if (w) + w->updateSaturation (); } - else if (event->xproperty.atom == d->xBackgroundAtom[0] || - event->xproperty.atom == d->xBackgroundAtom[1]) + else if (event->xproperty.atom == priv->atoms.xBackground[0] || + event->xproperty.atom == priv->atoms.xBackground[1]) { - s = findScreenAtDisplay (d, event->xproperty.window); + s = findScreen (event->xproperty.window); if (s) - { - finiTexture (s, &s->backgroundTexture); - initTexture (s, &s->backgroundTexture); - - if (s->backgroundLoaded) - { - s->backgroundLoaded = FALSE; - damageScreen (s); - } - } + s->updateBackground (); } - else if (event->xproperty.atom == d->wmStrutAtom || - event->xproperty.atom == d->wmStrutPartialAtom) + else if (event->xproperty.atom == priv->atoms.wmStrut || + event->xproperty.atom == priv->atoms.wmStrutPartial) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) { - if (updateWindowStruts (w)) - updateWorkareaForScreen (w->screen); + if (w->updateStruts ()) + w->screen ()->updateWorkarea (); } } - else if (event->xproperty.atom == d->mwmHintsAtom) + else if (event->xproperty.atom == priv->atoms.mwmHints) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) - { - getMwmHints (d, w->id, &w->mwmFunc, &w->mwmDecor); - - recalcWindowActions (w); - } + w->updateMwmHints (); } - else if (event->xproperty.atom == d->wmProtocolsAtom) + else if (event->xproperty.atom == priv->atoms.wmProtocols) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) - w->protocols = getProtocols (d, w->id); + w->protocols () = getProtocols (w->id ()); } - else if (event->xproperty.atom == d->wmIconAtom) + else if (event->xproperty.atom == priv->atoms.wmIcon) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) - freeWindowIcons (w); + w->freeIcons (); } - else if (event->xproperty.atom == d->startupIdAtom) + else if (event->xproperty.atom == priv->atoms.startupId) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) - { - if (w->startupId) - free (w->startupId); - - w->startupId = getStartupId (w); - } + w->updateStartupId (); } else if (event->xproperty.atom == XA_WM_CLASS) { - w = findWindowAtDisplay (d, event->xproperty.window); + w = findWindow (event->xproperty.window); if (w) - updateWindowClassHints (w); + w->updateClassHints (); } break; case MotionNotify: break; case ClientMessage: - if (event->xclient.message_type == d->winActiveAtom) + if (event->xclient.message_type == priv->atoms.winActive) { - w = findWindowAtDisplay (d, event->xclient.window); + w = findWindow (event->xclient.window); if (w) { /* use focus stealing prevention if request came from an application (which means data.l[0] is 1 */ if (event->xclient.data.l[0] != 1 || - allowWindowFocus (w, 0, event->xclient.data.l[1])) + w->allowWindowFocus (0, event->xclient.data.l[1])) { - (*w->screen->activateWindow) (w); + w->activate (); } } } - else if (event->xclient.message_type == d->winOpacityAtom) + else if (event->xclient.message_type == priv->atoms.winOpacity) { - w = findWindowAtDisplay (d, event->xclient.window); - if (w && (w->type & CompWindowTypeDesktopMask) == 0) + w = findWindow (event->xclient.window); + if (w && (w->type () & CompWindowTypeDesktopMask) == 0) { GLushort opacity = event->xclient.data.l[0] >> 16; - setWindowProp32 (d, w->id, d->winOpacityAtom, opacity); + setWindowProp32 (w->id (), priv->atoms.winOpacity, opacity); } } - else if (event->xclient.message_type == d->winBrightnessAtom) + else if (event->xclient.message_type == priv->atoms.winBrightness) { - w = findWindowAtDisplay (d, event->xclient.window); + w = findWindow (event->xclient.window); if (w) { GLushort brightness = event->xclient.data.l[0] >> 16; - setWindowProp32 (d, w->id, d->winBrightnessAtom, brightness); + setWindowProp32 (w->id (), priv->atoms.winBrightness, + brightness); } } - else if (event->xclient.message_type == d->winSaturationAtom) + else if (event->xclient.message_type == priv->atoms.winSaturation) { - w = findWindowAtDisplay (d, event->xclient.window); - if (w && w->screen->canDoSaturated) + w = findWindow (event->xclient.window); + if (w) { GLushort saturation = event->xclient.data.l[0] >> 16; - setWindowProp32 (d, w->id, d->winSaturationAtom, saturation); + setWindowProp32 (w->id (), priv->atoms.winSaturation, + saturation); } } - else if (event->xclient.message_type == d->winStateAtom) + else if (event->xclient.message_type == priv->atoms.winState) { - w = findWindowAtDisplay (d, event->xclient.window); + w = findWindow (event->xclient.window); if (w) { unsigned long wState, state; int i; - wState = w->state; + wState = w->state (); for (i = 1; i < 3; i++) { - state = windowStateMask (d, event->xclient.data.l[i]); + state = windowStateMask (event->xclient.data.l[i]); if (state & ~CompWindowStateHiddenMask) { @@ -1731,14 +1594,15 @@ handleEvent (CompDisplay *d, } } - wState = constrainWindowState (wState, w->actions); - if (w->id == d->activeWindow) + wState = CompWindow::constrainWindowState (wState, + w->actions ()); + if (w->id () == priv->activeWindow) wState &= ~CompWindowStateDemandsAttentionMask; - if (wState != w->state) + if (wState != w->state ()) { CompStackingUpdateMode stackingUpdateMode; - unsigned long dState = wState ^ w->state; + unsigned long dState = wState ^ w->state (); stackingUpdateMode = CompStackingUpdateModeNone; @@ -1751,69 +1615,46 @@ handleEvent (CompDisplay *d, CompWindowStateMaximizedVertMask)) stackingUpdateMode = CompStackingUpdateModeNormal; - changeWindowState (w, wState); + w->changeState (wState); - updateWindowAttributes (w, stackingUpdateMode); + w->updateAttributes (stackingUpdateMode); } } } - else if (event->xclient.message_type == d->wmProtocolsAtom) + else if (event->xclient.message_type == priv->atoms.wmProtocols) { - if (event->xclient.data.l[0] == d->wmPingAtom) + if (event->xclient.data.l[0] == priv->atoms.wmPing) { - w = findWindowAtDisplay (d, event->xclient.data.l[2]); + w = findWindow (event->xclient.data.l[2]); if (w) - { - if (!w->alive) - { - w->alive = TRUE; - w->paint.saturation = w->saturation; - w->paint.brightness = w->brightness; - - if (w->lastCloseRequestTime) - { - toolkitAction (w->screen, - d->toolkitActionForceQuitDialogAtom, - w->lastCloseRequestTime, - w->id, - FALSE, - 0, - 0); - - w->lastCloseRequestTime = 0; - } - - addWindowDamage (w); - } - w->lastPong = d->lastPing; - } + w->handlePing (priv->lastPing); } } - else if (event->xclient.message_type == d->closeWindowAtom) + else if (event->xclient.message_type == priv->atoms.closeWindow) { - w = findWindowAtDisplay (d, event->xclient.window); + w = findWindow (event->xclient.window); if (w) - closeWindow (w, event->xclient.data.l[0]); + w->close (event->xclient.data.l[0]); } - else if (event->xclient.message_type == d->desktopGeometryAtom) + else if (event->xclient.message_type == priv->atoms.desktopGeometry) { - s = findScreenAtDisplay (d, event->xclient.window); + s = findScreen (event->xclient.window); if (s) { CompOptionValue value; - value.i = event->xclient.data.l[0] / s->width; + value.i = event->xclient.data.l[0] / s->width (); - (*core.setOptionForPlugin) (&s->base, "core", "hsize", &value); + core->setOptionForPlugin (s, "core", "hsize", &value); - value.i = event->xclient.data.l[1] / s->height; + value.i = event->xclient.data.l[1] / s->height (); - (*core.setOptionForPlugin) (&s->base, "core", "vsize", &value); + core->setOptionForPlugin (s, "core", "vsize", &value); } } - else if (event->xclient.message_type == d->moveResizeWindowAtom) + else if (event->xclient.message_type == priv->atoms.moveResizeWindow) { - w = findWindowAtDisplay (d, event->xclient.window); + w = findWindow (event->xclient.window); if (w) { unsigned int xwcm = 0; @@ -1848,12 +1689,12 @@ handleEvent (CompDisplay *d, gravity = event->xclient.data.l[0] & 0xFF; - moveResizeWindow (w, &xwc, xwcm, gravity); + w->moveResize (&xwc, xwcm, gravity); } } - else if (event->xclient.message_type == d->restackWindowAtom) + else if (event->xclient.message_type == priv->atoms.restackWindow) { - w = findWindowAtDisplay (d, event->xclient.window); + w = findWindow (event->xclient.window); if (w) { /* TODO: other stack modes than Above and Below */ @@ -1861,186 +1702,121 @@ handleEvent (CompDisplay *d, { CompWindow *sibling; - sibling = findWindowAtDisplay (d, event->xclient.data.l[1]); + sibling = findWindow (event->xclient.data.l[1]); if (sibling) { if (event->xclient.data.l[2] == Above) - restackWindowAbove (w, sibling); + w->restackAbove (sibling); else if (event->xclient.data.l[2] == Below) - restackWindowBelow (w, sibling); + w->restackBelow (sibling); } } else { if (event->xclient.data.l[2] == Above) - raiseWindow (w); + w->raise (); else if (event->xclient.data.l[2] == Below) - lowerWindow (w); + w->lower (); } } } - else if (event->xclient.message_type == d->wmChangeStateAtom) + else if (event->xclient.message_type == priv->atoms.wmChangeState) { - w = findWindowAtDisplay (d, event->xclient.window); + w = findWindow (event->xclient.window); if (w) { if (event->xclient.data.l[0] == IconicState) { - if (w->actions & CompWindowActionMinimizeMask) - minimizeWindow (w); + if (w->actions () & CompWindowActionMinimizeMask) + w->minimize (); } else if (event->xclient.data.l[0] == NormalState) - unminimizeWindow (w); + w->unminimize (); } } - else if (event->xclient.message_type == d->showingDesktopAtom) + else if (event->xclient.message_type == priv->atoms.showingDesktop) { - for (s = d->screens; s; s = s->next) + for (s = priv->screens; s; s = s->next) { - if (event->xclient.window == s->root || + if (event->xclient.window == s->root () || event->xclient.window == None) { if (event->xclient.data.l[0]) - (*s->enterShowDesktopMode) (s); + s->enterShowDesktopMode (); else - (*s->leaveShowDesktopMode) (s, NULL); + s->leaveShowDesktopMode (NULL); } } } - else if (event->xclient.message_type == d->numberOfDesktopsAtom) + else if (event->xclient.message_type == priv->atoms.numberOfDesktops) { - s = findScreenAtDisplay (d, event->xclient.window); + s = findScreen (event->xclient.window); if (s) { CompOptionValue value; value.i = event->xclient.data.l[0]; - (*core.setOptionForPlugin) (&s->base, - "core", "number_of_desktops", - &value); + core->setOptionForPlugin (s, "core", "number_of_desktops", + &value); } } - else if (event->xclient.message_type == d->currentDesktopAtom) + else if (event->xclient.message_type == priv->atoms.currentDesktop) { - s = findScreenAtDisplay (d, event->xclient.window); + s = findScreen (event->xclient.window); if (s) - setCurrentDesktop (s, event->xclient.data.l[0]); + s->setCurrentDesktop (event->xclient.data.l[0]); } - else if (event->xclient.message_type == d->winDesktopAtom) + else if (event->xclient.message_type == priv->atoms.winDesktop) { - w = findWindowAtDisplay (d, event->xclient.window); + w = findWindow (event->xclient.window); if (w) - setDesktopForWindow (w, event->xclient.data.l[0]); + w->setDesktop (event->xclient.data.l[0]); } break; case MappingNotify: - updateModifierMappings (d); + updateModifierMappings (); break; case MapRequest: - w = findWindowAtDisplay (d, event->xmaprequest.window); + w = findWindow (event->xmaprequest.window); if (w) { XWindowAttributes attr; - Bool doMapProcessing = TRUE; + bool doMapProcessing = true; /* We should check the override_redirect flag here, because the client might have changed it while being unmapped. */ - if (XGetWindowAttributes (d->display, w->id, &attr)) + if (XGetWindowAttributes (priv->dpy, w->id (), &attr)) { - if (w->attrib.override_redirect != attr.override_redirect) + if (w->attrib ().override_redirect != attr.override_redirect) { - w->attrib.override_redirect = attr.override_redirect; - recalcWindowType (w); - recalcWindowActions (w); + w->attrib ().override_redirect = attr.override_redirect; + w->recalcType (); + w->recalcActions (); - (*d->matchPropertyChanged) (d, w); + matchPropertyChanged (w); } } - w->managed = TRUE; + w->managed () = true; - if (w->state & CompWindowStateHiddenMask) - if (!w->minimized && !w->inShowDesktopMode) - doMapProcessing = FALSE; + if (w->state () & CompWindowStateHiddenMask) + if (!w->minimized () && !w->inShowDesktopMode ()) + doMapProcessing = false; if (doMapProcessing) - { - Bool allowFocus; - CompStackingUpdateMode stackingMode; - - w->initialViewportX = w->screen->x; - w->initialViewportY = w->screen->y; - - w->initialTimestampSet = FALSE; - - applyStartupProperties (w->screen, w); - - if (!w->placed) - { - int newX, newY; - int gravity = w->sizeHints.win_gravity; - XWindowChanges xwc; - unsigned int xwcm; - - /* adjust for gravity */ - xwc.x = w->serverX; - xwc.y = w->serverY; - xwc.width = w->serverWidth; - xwc.height = w->serverHeight; - - xwcm = adjustConfigureRequestForGravity (w, &xwc, - CWX | CWY, - gravity); - - if ((*w->screen->placeWindow) (w, xwc.x, xwc.y, - &newX, &newY)) - { - xwc.x = newX; - xwc.y = newY; - xwcm |= CWX | CWY; - } - - if (xwcm) - configureXWindow (w, xwcm, &xwc); - - w->placed = TRUE; - } - - allowFocus = allowWindowFocus (w, NO_FOCUS_MASK, 0); - - if (!allowFocus && (w->type & ~NO_FOCUS_MASK)) - stackingMode = CompStackingUpdateModeInitialMapDeniedFocus; - else - stackingMode = CompStackingUpdateModeInitialMap; + w->processMap (); - updateWindowAttributes (w, stackingMode); - - if (w->minimized) - unminimizeWindow (w); - - (*w->screen->leaveShowDesktopMode) (w->screen, w); - - if (!(w->state & CompWindowStateHiddenMask)) - { - w->pendingMaps++; - XMapWindow (d->display, w->id); - } - - if (allowFocus) - moveInputFocusToWindow (w); - } - - setWindowProp (d, w->id, d->winDesktopAtom, w->desktop); + setWindowProp (w->id (), priv->atoms.winDesktop, w->desktop ()); } else { - XMapWindow (d->display, event->xmaprequest.window); + XMapWindow (priv->dpy, event->xmaprequest.window); } break; case ConfigureRequest: - w = findWindowAtDisplay (d, event->xconfigurerequest.window); - if (w && w->managed) + w = findWindow (event->xconfigurerequest.window); + if (w && w->managed ()) { XWindowChanges xwc; @@ -2052,7 +1828,7 @@ handleEvent (CompDisplay *d, xwc.height = event->xconfigurerequest.height; xwc.border_width = event->xconfigurerequest.border_width; - moveResizeWindow (w, &xwc, event->xconfigurerequest.value_mask, 0); + w->moveResize (&xwc, event->xconfigurerequest.value_mask, 0); if (event->xconfigurerequest.value_mask & CWStackMode) { @@ -2062,30 +1838,30 @@ handleEvent (CompDisplay *d, if (event->xconfigurerequest.value_mask & CWSibling) { above = event->xconfigurerequest.above; - sibling = findTopLevelWindowAtDisplay (d, above); + sibling = findTopLevelWindow (above); } switch (event->xconfigurerequest.detail) { case Above: - if (allowWindowFocus (w, NO_FOCUS_MASK, 0)) + if (w->allowWindowFocus (NO_FOCUS_MASK, 0)) { if (above) { if (sibling) - restackWindowAbove (w, sibling); + w->restackAbove (sibling); } else - raiseWindow (w); + w->raise (); } break; case Below: if (above) { if (sibling) - restackWindowBelow (w, sibling); + w->restackBelow (sibling); } else - lowerWindow (w); + w->lower (); break; default: /* no handling of the TopIf, BottomIf, Opposite cases - @@ -2109,9 +1885,9 @@ handleEvent (CompDisplay *d, xwc.border_width = event->xconfigurerequest.border_width; if (w) - configureXWindow (w, xwcm, &xwc); + w->configureXWindow (xwcm, &xwc); else - XConfigureWindow (d->display, event->xconfigurerequest.window, + XConfigureWindow (priv->dpy, event->xconfigurerequest.window, xwcm, &xwc); } break; @@ -2120,31 +1896,31 @@ handleEvent (CompDisplay *d, case FocusIn: if (event->xfocus.mode != NotifyGrab) { - w = findTopLevelWindowAtDisplay (d, event->xfocus.window); - if (w && w->managed) + w = findTopLevelWindow (event->xfocus.window); + if (w && w->managed ()) { - unsigned int state = w->state; + unsigned int state = w->state (); - if (w->id != d->activeWindow) + if (w->id () != priv->activeWindow) { - d->activeWindow = w->id; - w->activeNum = w->screen->activeNum++; + priv->activeWindow = w->id (); + w->activeNum () = w->screen ()->activeNum ()++; - addToCurrentActiveWindowHistory (w->screen, w->id); + w->screen ()->addToCurrentActiveWindowHistory (w->id ()); - XChangeProperty (d->display, w->screen->root, - d->winActiveAtom, + XChangeProperty (priv->dpy , w->screen ()->root (), + priv->atoms.winActive, XA_WINDOW, 32, PropModeReplace, - (unsigned char *) &w->id, 1); + (unsigned char *) &priv->activeWindow, 1); } state &= ~CompWindowStateDemandsAttentionMask; - changeWindowState (w, state); + w->changeState (state); } } break; case EnterNotify: - if (!d->screens->maxGrab && + if (!priv->screens->maxGrab () && event->xcrossing.mode != NotifyGrab && event->xcrossing.mode != NotifyUngrab && event->xcrossing.detail != NotifyInferior) @@ -2152,50 +1928,50 @@ handleEvent (CompDisplay *d, Bool raise; int delay; - raise = d->opt[COMP_DISPLAY_OPTION_AUTORAISE].value.b; - delay = d->opt[COMP_DISPLAY_OPTION_AUTORAISE_DELAY].value.i; + raise = priv->opt[COMP_DISPLAY_OPTION_AUTORAISE].value.b; + delay = priv->opt[COMP_DISPLAY_OPTION_AUTORAISE_DELAY].value.i; - s = findScreenAtDisplay (d, event->xcrossing.root); + s = findScreen (event->xcrossing.root); if (s) { - w = findTopLevelWindowAtScreen (s, event->xcrossing.window); + w = s->findTopLevelWindow (event->xcrossing.window); } else w = NULL; - if (w && w->id != d->below) + if (w && w->id () != priv->below) { - d->below = w->id; + priv->below = w->id (); - if (!d->opt[COMP_DISPLAY_OPTION_CLICK_TO_FOCUS].value.b) + if (!priv->opt[COMP_DISPLAY_OPTION_CLICK_TO_FOCUS].value.b) { - if (d->autoRaiseHandle && - d->autoRaiseWindow != w->id) + if (priv->autoRaiseHandle && + priv->autoRaiseWindow != w->id ()) { - compRemoveTimeout (d->autoRaiseHandle); - d->autoRaiseHandle = 0; + core->removeTimeout (priv->autoRaiseHandle); + priv->autoRaiseHandle = 0; } - if (w->type & ~(CompWindowTypeDockMask | - CompWindowTypeDesktopMask)) + if (w->type () & ~(CompWindowTypeDockMask | + CompWindowTypeDesktopMask)) { - moveInputFocusToWindow (w); + w->moveInputFocusTo (); if (raise) { if (delay > 0) { - d->autoRaiseWindow = w->id; - d->autoRaiseHandle = - compAddTimeout (delay, (float) delay * 1.2, - autoRaiseTimeout, d); + priv->autoRaiseWindow = w->id (); + priv->autoRaiseHandle = + core->addTimeout (delay, (float) delay * 1.2, + autoRaiseTimeout, this); } else { CompStackingUpdateMode mode = CompStackingUpdateModeNormal; - updateWindowAttributes (w, mode); + w->updateAttributes (mode); } } } @@ -2206,82 +1982,55 @@ handleEvent (CompDisplay *d, case LeaveNotify: if (event->xcrossing.detail != NotifyInferior) { - if (event->xcrossing.window == d->below) - d->below = None; + if (event->xcrossing.window == priv->below) + priv->below = None; } break; default: - if (event->type == d->damageEvent + XDamageNotify) + if (event->type == priv->damageEvent + XDamageNotify) { XDamageNotifyEvent *de = (XDamageNotifyEvent *) event; - if (lastDamagedWindow && de->drawable == lastDamagedWindow->id) + if (lastDamagedWindow && de->drawable == lastDamagedWindow->id ()) { w = lastDamagedWindow; } else { - w = findWindowAtDisplay (d, de->drawable); + w = findWindow (de->drawable); if (w) lastDamagedWindow = w; } if (w) - { - w->texture->oldMipmaps = TRUE; - - if (w->syncWait) - { - if (w->nDamage == w->sizeDamage) - { - w->damageRects = (XRectangle *) realloc (w->damageRects, - (w->sizeDamage + 1) * - sizeof (XRectangle)); - w->sizeDamage += 1; - } - - w->damageRects[w->nDamage].x = de->area.x; - w->damageRects[w->nDamage].y = de->area.y; - w->damageRects[w->nDamage].width = de->area.width; - w->damageRects[w->nDamage].height = de->area.height; - w->nDamage++; - } - else - { - handleWindowDamageRect (w, - de->area.x, - de->area.y, - de->area.width, - de->area.height); - } - } + w->processDamage (de); } - else if (d->shapeExtension && - event->type == d->shapeEvent + ShapeNotify) + else if (priv->shapeExtension && + event->type == priv->shapeEvent + ShapeNotify) { - w = findWindowAtDisplay (d, ((XShapeEvent *) event)->window); + w = findWindow (((XShapeEvent *) event)->window); if (w) { - if (w->mapNum) + if (w->mapNum ()) { - addWindowDamage (w); - updateWindowRegion (w); - addWindowDamage (w); + w->addDamage (); + w->updateRegion (); + w->addDamage (); } } } - else if (d->randrExtension && - event->type == d->randrEvent + RRScreenChangeNotify) + else if (priv->randrExtension && + event->type == priv->randrEvent + RRScreenChangeNotify) { XRRScreenChangeNotifyEvent *rre; rre = (XRRScreenChangeNotifyEvent *) event; - s = findScreenAtDisplay (d, rre->root); + s = findScreen (rre->root); if (s) - detectRefreshRateOfScreen (s); + s->detectRefreshRate (); } - else if (event->type == d->syncEvent + XSyncAlarmNotify) + else if (event->type == priv->syncEvent + XSyncAlarmNotify) { XSyncAlarmNotifyEvent *sa; @@ -2289,13 +2038,13 @@ handleEvent (CompDisplay *d, w = NULL; - for (s = d->screens; s; s = s->next) - for (w = s->windows; w; w = w->next) - if (w->syncAlarm == sa->alarm) + for (s = priv->screens; s; s = s->next) + for (w = s->windows (); w; w = w->next) + if (w->syncAlarm () == sa->alarm) break; if (w) - handleSyncAlarm (w); + w->handleSyncAlarm (); } break; } diff --git a/src/fragment.cpp b/src/fragment.cpp index 99c38cc..32794ef 100644 --- a/src/fragment.cpp +++ b/src/fragment.cpp @@ -160,7 +160,7 @@ findFragmentFunction (CompScreen *s, { CompFunction *function; - for (function = s->fragmentFunctions; function; function = function->next) + for (function = s->fragmentFunctions (); function; function = function->next) { if (function->id == id) return function; @@ -175,7 +175,7 @@ findFragmentFunctionWithName (CompScreen *s, { CompFunction *function; - for (function = s->fragmentFunctions; function; function = function->next) + for (function = s->fragmentFunctions (); function; function = function->next) { if (strcmp (function->name, name) == 0) return function; @@ -192,7 +192,7 @@ findFragmentProgram (CompScreen *s, CompProgram *program; int i; - for (program = s->fragmentPrograms; program; program = program->next) + for (program = s->fragmentPrograms (); program; program = program->next) { if (nSignature != program->nSignature) continue; @@ -671,8 +671,8 @@ getFragmentProgram (CompScreen *s, program = buildFragmentProgram (s, attrib); if (program) { - program->next = s->fragmentPrograms; - s->fragmentPrograms = program; + program->next = s->fragmentPrograms (); + s->fragmentPrograms () = program; } } @@ -1140,7 +1140,7 @@ addBlendOpToFunctionData (CompFunctionData *data, static int allocFunctionId (CompScreen *s) { - return ++s->lastFunctionId; + return ++s->lastFunctionId (); } int @@ -1190,8 +1190,8 @@ createFragmentFunction (CompScreen *s, function->mask = COMP_FUNCTION_ARB_MASK; function->id = allocFunctionId (s); - function->next = s->fragmentFunctions; - s->fragmentFunctions = function; + function->next = s->fragmentFunctions (); + s->fragmentFunctions () = function; if (nameBuffer) free (nameBuffer); @@ -1207,7 +1207,7 @@ destroyFragmentFunction (CompScreen *s, CompProgram *program, *prevProgram = NULL; int i; - for (function = s->fragmentFunctions; function; function = function->next) + for (function = s->fragmentFunctions (); function; function = function->next) { if (function->id == id) break; @@ -1218,7 +1218,7 @@ destroyFragmentFunction (CompScreen *s, if (!function) return; - program = s->fragmentPrograms; + program = s->fragmentPrograms (); while (program) { for (i = 0; i < program->nSignature; i++) @@ -1234,7 +1234,7 @@ destroyFragmentFunction (CompScreen *s, if (prevProgram) prevProgram->next = program->next; else - s->fragmentPrograms = program->next; + s->fragmentPrograms () = program->next; program = program->next; @@ -1253,7 +1253,7 @@ destroyFragmentFunction (CompScreen *s, if (prevFunction) prevFunction->next = function->next; else - s->fragmentFunctions = function->next; + s->fragmentFunctions () = function->next; finiFunctionData (&function->data[COMP_FUNCTION_TYPE_ARB]); free (function->name); @@ -1275,7 +1275,7 @@ getSaturateFragmentFunction (CompScreen *s, else target = COMP_FETCH_TARGET_RECT; - if (!s->saturateFunction[target][param]) + if (!s->getSaturateFunction (target, param)) { static const char *saturateData = "MUL temp, output, { 1.0, 1.0, 1.0, 0.0 };" @@ -1314,14 +1314,14 @@ getSaturateFragmentFunction (CompScreen *s, return 0; } - s->saturateFunction[target][param] = + s->getSaturateFunction (target, param) = createFragmentFunction (s, "__core_saturate", data); destroyFunctionData (data); } } - return s->saturateFunction[target][param]; + return s->getSaturateFunction (target, param); } int @@ -1369,7 +1369,7 @@ initFragmentAttrib (FragmentAttrib *attrib, memset (attrib->function, 0, sizeof (attrib->function)); } -Bool +bool enableFragmentAttrib (CompScreen *s, FragmentAttrib *attrib, Bool *blending) @@ -1378,12 +1378,12 @@ enableFragmentAttrib (CompScreen *s, GLenum type; Bool programBlending; - if (!s->fragmentProgram) - return FALSE; + if (!s->fragmentProgram ()) + return false; name = getFragmentProgram (s, attrib, &type, &programBlending); if (!name) - return FALSE; + return false; *blending = !programBlending; @@ -1391,7 +1391,7 @@ enableFragmentAttrib (CompScreen *s, (*s->bindProgram) (type, name); - return TRUE; + return true; } void diff --git a/src/main.cpp b/src/main.cpp index 6ca3bb4..3629c88 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,59 +98,6 @@ usage (void) programName); } -void -compLogMessage (CompDisplay *d, - const char *componentName, - CompLogLevel level, - const char *format, - ...) -{ - va_list args; - char message[2048]; - - va_start (args, format); - - vsnprintf (message, 2048, format, args); - - if (d) - (*d->logMessage) (d, componentName, level, message); - else - logMessage (d, componentName, level, message); - - va_end (args); -} - -void -logMessage (CompDisplay *d, - const char *componentName, - CompLogLevel level, - const char *message) -{ - fprintf (stderr, "%s (%s) - %s: %s\n", - programName, componentName, - logLevelToString (level), message); -} - -const char * -logLevelToString (CompLogLevel level) -{ - switch (level) { - case CompLogLevelFatal: - return "Fatal"; - case CompLogLevelError: - return "Error"; - case CompLogLevelWarn: - return "Warn"; - case CompLogLevelInfo: - return "Info"; - case CompLogLevelDebug: - return "Debug"; - default: - break; - } - - return "Unknown"; -} static void signalHandler (int sig) @@ -425,21 +372,26 @@ main (int argc, char **argv) compAddMetadataFromFile (&coreMetadata, "core"); - if (!initCore ()) + core = new CompCore(); + + if (!core) + return 1; + + if (!core->init ()) return 1; if (!disableSm) initSession (clientId); - if (!addDisplay (displayName)) + if (!core->addDisplay (displayName)) return 1; - eventLoop (); + core->eventLoop (); if (!disableSm) closeSession (); - finiCore (); + delete core; compFiniMetadata (&coreMetadata); xmlCleanupParser (); diff --git a/src/match.cpp b/src/match.cpp index 935ec50..e8697df 100644 --- a/src/match.cpp +++ b/src/match.cpp @@ -27,6 +27,7 @@ #include <string.h> #include <compiz-core.h> +#include "privatedisplay.h" static void matchResetOps (CompDisplay *display, @@ -563,7 +564,7 @@ matchUpdateOps (CompDisplay *display, matchUpdateOps (display, op->group.op, op->group.nOp); break; case CompMatchOpTypeExp: - (*display->matchInitExp) (display, &op->exp.e, op->exp.value); + display->matchInitExp (&op->exp.e, op->exp.value); break; } @@ -643,7 +644,7 @@ matchEvalTypeExp (CompDisplay *display, CompWindow *window, CompPrivate c_private) { - return (c_private.uval & window->wmType); + return (c_private.uval & window->wmType ()); } static Bool @@ -651,7 +652,7 @@ matchEvalStateExp (CompDisplay *display, CompWindow *window, CompPrivate c_private) { - return (c_private.uval & window->state); + return (c_private.uval & window->state ()); } static Bool @@ -659,7 +660,7 @@ matchEvalIdExp (CompDisplay *display, CompWindow *window, CompPrivate c_private) { - return (c_private.val == window->id); + return (c_private.val == window->id ()); } static Bool @@ -667,16 +668,16 @@ matchEvalOverrideRedirectExp (CompDisplay *display, CompWindow *window, CompPrivate c_private) { - Bool overrideRedirect = window->attrib.override_redirect; + Bool overrideRedirect = window->attrib ().override_redirect; return ((c_private.val == 1 && overrideRedirect) || (c_private.val == 0 && !overrideRedirect)); } void -matchInitExp (CompDisplay *display, - CompMatchExp *exp, - const char *value) +CompDisplay::matchInitExp (CompMatchExp *exp, const char *value) { + WRAPABLE_HND_FUNC(matchInitExp, exp, value) + if (strncmp (value, "xid=", 4) == 0) { exp->eval = matchEvalIdExp; @@ -698,7 +699,7 @@ matchInitExp (CompDisplay *display, value += 5; exp->eval = matchEvalTypeExp; - exp->priv.uval = windowTypeFromString (value); + exp->priv.uval = CompWindow::windowTypeFromString (value); } } @@ -732,8 +733,10 @@ matchUpdateMatchOptions (CompOption *option, } void -matchExpHandlerChanged (CompDisplay *display) +CompDisplay::matchExpHandlerChanged () { + WRAPABLE_HND_FUNC(matchExpHandlerChanged) + CompOption *option; int nOption; CompPlugin *p; @@ -742,32 +745,22 @@ matchExpHandlerChanged (CompDisplay *display) for (p = getPlugins (); p; p = p->next) { - if (!p->vTable->getObjectOptions) - continue; - - option = (*p->vTable->getObjectOptions) (p, &display->base, &nOption); + option = p->vTable->getObjectOptions (this, &nOption); matchUpdateMatchOptions (option, nOption); } - for (s = display->screens; s; s = s->next) + for (s = priv->screens; s; s = s->next) { for (p = getPlugins (); p; p = p->next) { - if (!p->vTable->getObjectOptions) - continue; - - option = (*p->vTable->getObjectOptions) (p, &s->base, &nOption); + option = p->vTable->getObjectOptions (s, &nOption); matchUpdateMatchOptions (option, nOption); } - - for (w = s->windows; w; w = w->next) - updateWindowOpacity (w); } } void -matchPropertyChanged (CompDisplay *display, - CompWindow *w) +CompDisplay::matchPropertyChanged (CompWindow *w) { - updateWindowOpacity (w); + WRAPABLE_HND_FUNC(matchPropertyChanged, w) } diff --git a/src/metadata.cpp b/src/metadata.cpp index 5e7d365..88bdce6 100644 --- a/src/metadata.cpp +++ b/src/metadata.cpp @@ -597,8 +597,8 @@ initKeyValue (CompDisplay *d, { CompScreen *s; - for (s = d->screens; s; s = s->next) - addScreenAction (s, &v->action); + for (s = d->screens (); s; s = s->next) + s->addAction (&v->action); } } @@ -634,8 +634,8 @@ initButtonValue (CompDisplay *d, { CompScreen *s; - for (s = d->screens; s; s = s->next) - addScreenAction (s, &v->action); + for (s = d->screens (); s; s = s->next) + s->addAction (&v->action); } } @@ -675,8 +675,8 @@ initEdgeValue (CompDisplay *d, { CompScreen *s; - for (s = d->screens; s; s = s->next) - addScreenAction (s, &v->action); + for (s = d->screens (); s; s = s->next) + s->addAction (&v->action); } } @@ -1106,7 +1106,7 @@ compInitScreenOptionFromMetadata (CompScreen *s, sprintf (str, "/compiz/%s/screen//option[@name=\"%s\"]", m->path, name); - return initOptionFromMetadataPath (s->display, m, o, BAD_CAST str); + return initOptionFromMetadataPath (s->display (), m, o, BAD_CAST str); } static void @@ -1123,7 +1123,7 @@ finiScreenOptionValue (CompScreen *s, case CompOptionTypeEdge: case CompOptionTypeBell: if (v->action.state & CompActionStateAutoGrab) - removeScreenAction (s, &v->action); + s->removeAction (&v->action); break; case CompOptionTypeList: for (i = 0; i < v->list.nValue; i++) @@ -1219,8 +1219,8 @@ finiDisplayOptionValue (CompDisplay *d, case CompOptionTypeEdge: case CompOptionTypeBell: if (v->action.state & CompActionStateAutoGrab) - for (s = d->screens; s; s = s->next) - removeScreenAction (s, &v->action); + for (s = d->screens (); s; s = s->next) + s->removeAction (&v->action); break; case CompOptionTypeList: for (i = 0; i < v->list.nValue; i++) diff --git a/src/option.cpp b/src/option.cpp index 1c704fc..c976b70 100644 --- a/src/option.cpp +++ b/src/option.cpp @@ -605,7 +605,7 @@ keyBindingToString (CompDisplay *d, KeySym keysym; char *keyname; - keysym = XKeycodeToKeysym (d->display, key->keycode, 0); + keysym = XKeycodeToKeysym (d->dpy (), key->keycode, 0); keyname = XKeysymToString (keysym); if (keyname) @@ -743,7 +743,7 @@ stringToKeyBinding (CompDisplay *d, { KeyCode keycode; - keycode = XKeysymToKeycode (d->display, keysym); + keycode = XKeysymToKeycode (d->dpy (), keysym); if (keycode) { key->keycode = keycode; diff --git a/src/paint.cpp b/src/paint.cpp index 30b492e..a4d1453 100644 --- a/src/paint.cpp +++ b/src/paint.cpp @@ -29,6 +29,9 @@ #include <compiz-core.h> +#include "privatescreen.h" +#include "privatewindow.h" + ScreenPaintAttrib defaultScreenPaintAttrib = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -DEFAULT_Z_CAMERA }; @@ -38,22 +41,20 @@ WindowPaintAttrib defaultWindowPaintAttrib = { }; void -preparePaintScreen (CompScreen *screen, - int msSinceLastPaint) -{ -} +CompScreen::preparePaint (int msSinceLastPaint) + WRAPABLE_HND_FUNC(preparePaint, msSinceLastPaint) void -donePaintScreen (CompScreen *screen) -{ -} +CompScreen::donePaint () + WRAPABLE_HND_FUNC(donePaint) void -applyScreenTransform (CompScreen *screen, - const ScreenPaintAttrib *sAttrib, - CompOutput *output, - CompTransform *transform) +CompScreen::applyTransform (const ScreenPaintAttrib *sAttrib, + CompOutput *output, + CompTransform *transform) { + WRAPABLE_HND_FUNC(applyTransform, sAttrib, output, transform) + matrixTranslate (transform, sAttrib->xTranslate, sAttrib->yTranslate, @@ -101,11 +102,13 @@ prepareXCoords (CompScreen *screen, } void -paintCursor (CompCursor *c, - const CompTransform *transform, - Region region, - unsigned int mask) +CompScreen::paintCursor (CompCursor *c, + const CompTransform *transform, + Region region, + unsigned int mask) { + WRAPABLE_HND_FUNC(paintCursor, c, transform, region, mask) + int x1, y1, x2, y2; if (!c->image) @@ -119,7 +122,7 @@ paintCursor (CompCursor *c, glDisableClientState (GL_TEXTURE_COORD_ARRAY); glEnable (GL_BLEND); - enableTexture (c->screen, &c->image->texture, COMP_TEXTURE_FILTER_FAST); + c->screen->enableTexture (&c->image->texture, COMP_TEXTURE_FILTER_FAST); glBegin (GL_QUADS); @@ -138,18 +141,17 @@ paintCursor (CompCursor *c, glEnd (); - disableTexture (c->screen, &c->image->texture); + c->screen->disableTexture (&c->image->texture); glDisable (GL_BLEND); glEnableClientState (GL_TEXTURE_COORD_ARRAY); } -static void -paintBackground (CompScreen *s, - Region region, - Bool transformed) +void +PrivateScreen::paintBackground (Region region, + bool transformed) { - CompTexture *bg = &s->backgroundTexture; + CompTexture *bg = &backgroundTexture; BoxPtr pBox = region->rects; int n, nBox = region->numRects; GLfloat *d, *data; @@ -157,24 +159,24 @@ paintBackground (CompScreen *s, if (!nBox) return; - if (s->desktopWindowCount) + if (desktopWindowCount) { if (bg->name) { - finiTexture (s, bg); - initTexture (s, bg); + finiTexture (screen, bg); + initTexture (screen, bg); } - s->backgroundLoaded = FALSE; + backgroundLoaded = false; return; } else { - if (!s->backgroundLoaded) - updateScreenBackground (s, bg); + if (!backgroundLoaded) + updateScreenBackground (bg); - s->backgroundLoaded = TRUE; + backgroundLoaded = true; } data = (GLfloat *) malloc (sizeof (GLfloat) * nBox * 16); @@ -218,13 +220,13 @@ paintBackground (CompScreen *s, if (bg->name) { if (transformed) - enableTexture (s, bg, COMP_TEXTURE_FILTER_GOOD); + screen->enableTexture (bg, COMP_TEXTURE_FILTER_GOOD); else - enableTexture (s, bg, COMP_TEXTURE_FILTER_FAST); + screen->enableTexture (bg, COMP_TEXTURE_FILTER_FAST); glDrawArrays (GL_QUADS, 0, nBox * 4); - disableTexture (s, bg); + screen->disableTexture (bg); } else { @@ -244,12 +246,11 @@ paintBackground (CompScreen *s, difference with most hardware but occlusion detection in the transformed screen case should be made optional for those who do see a difference. */ -static void -paintOutputRegion (CompScreen *screen, - const CompTransform *transform, - Region region, - CompOutput *output, - unsigned int mask) +void +PrivateScreen::paintOutputRegion (const CompTransform *transform, + Region region, + CompOutput *output, + unsigned int mask) { static Region tmpRegion = NULL; CompWindow *w; @@ -257,8 +258,8 @@ paintOutputRegion (CompScreen *screen, int count, windowMask, odMask, i; CompWindow *fullscreenWindow = NULL; CompWalker walk; - Bool status; - Bool withOffset = FALSE; + bool status; + bool withOffset = false; CompTransform vTransform; int offX, offY; Region clip = region; @@ -283,77 +284,77 @@ paintOutputRegion (CompScreen *screen, XSubtractRegion (region, &emptyRegion, tmpRegion); - (*screen->initWindowWalker) (screen, &walk); + screen->initWindowWalker (&walk); if (!(mask & PAINT_SCREEN_NO_OCCLUSION_DETECTION_MASK)) { /* detect occlusions */ for (w = (*walk.last) (screen); w; w = (*walk.prev) (w)) { - if (w->destroyed) + if (w->destroyed ()) continue; - if (!w->shaded) + if (!w->shaded ()) { - if (w->attrib.map_state != IsViewable || !w->damaged) + if (w->attrib ().map_state != IsViewable || !w->damaged ()) continue; } /* copy region */ - XSubtractRegion (tmpRegion, &emptyRegion, w->clip); + XSubtractRegion (tmpRegion, &emptyRegion, w->clip ()); odMask = PAINT_WINDOW_OCCLUSION_DETECTION_MASK; - if ((screen->windowOffsetX != 0 || screen->windowOffsetY != 0) && - !windowOnAllViewports (w)) + if ((windowOffsetX != 0 || windowOffsetY != 0) && + !w->onAllViewports ()) { - withOffset = TRUE; + withOffset = true; - getWindowMovementForOffset (w, screen->windowOffsetX, - screen->windowOffsetY, - &offX, &offY); + w->getMovementForOffset (windowOffsetX, + windowOffsetY, + &offX, &offY); vTransform = *transform; matrixTranslate (&vTransform, offX, offY, 0); - XOffsetRegion (w->clip, -offX, -offY); + XOffsetRegion (w->clip (), -offX, -offY); odMask |= PAINT_WINDOW_WITH_OFFSET_MASK; - status = (*screen->paintWindow) (w, &w->paint, &vTransform, - tmpRegion, odMask); + status = w->paint (&w->paintAttrib (), &vTransform, + tmpRegion, odMask); } else { - withOffset = FALSE; - status = (*screen->paintWindow) (w, &w->paint, transform, tmpRegion, - odMask); + withOffset = false; + status = w->paint (&w->paintAttrib (), transform, tmpRegion, + odMask); } if (status) { if (withOffset) { - XOffsetRegion (w->region, offX, offY); - XSubtractRegion (tmpRegion, w->region, tmpRegion); - XOffsetRegion (w->region, -offX, -offY); + XOffsetRegion (w->region (), offX, offY); + XSubtractRegion (tmpRegion, w->region (), tmpRegion); + XOffsetRegion (w->region (), -offX, -offY); } else - XSubtractRegion (tmpRegion, w->region, tmpRegion); + XSubtractRegion (tmpRegion, w->region (), tmpRegion); /* unredirect top most fullscreen windows. */ if (count == 0 && - screen->opt[COMP_SCREEN_OPTION_UNREDIRECT_FS].value.b) + opt[COMP_SCREEN_OPTION_UNREDIRECT_FS].value.b) { - if (XEqualRegion (w->region, &screen->region) && + if (XEqualRegion (w->region (), &this->region) && !REGION_NOT_EMPTY (tmpRegion)) { fullscreenWindow = w; } else { - for (i = 0; i < screen->nOutputDev; i++) - if (XEqualRegion (w->region, - &screen->outputDev[i].region)) + for (i = 0; i < nOutputDev; i++) + if (XEqualRegion (w->region (), + &outputDev[i].region)) fullscreenWindow = w; } } @@ -364,45 +365,43 @@ paintOutputRegion (CompScreen *screen, } if (fullscreenWindow) - unredirectWindow (fullscreenWindow); + fullscreenWindow->unredirect (); if (!(mask & PAINT_SCREEN_NO_BACKGROUND_MASK)) - paintBackground (screen, tmpRegion, - (mask & PAINT_SCREEN_TRANSFORMED_MASK)); + paintBackground (tmpRegion, (mask & PAINT_SCREEN_TRANSFORMED_MASK)); /* paint all windows from bottom to top */ for (w = (*walk.first) (screen); w; w = (*walk.next) (w)) { - if (w->destroyed) + if (w->destroyed ()) continue; if (w == fullscreenWindow) continue; - if (!w->shaded) + if (!w->shaded ()) { - if (w->attrib.map_state != IsViewable || !w->damaged) + if (w->attrib ().map_state != IsViewable || !w->damaged ()) continue; } if (!(mask & PAINT_SCREEN_NO_OCCLUSION_DETECTION_MASK)) - clip = w->clip; + clip = w->clip (); - if ((screen->windowOffsetX != 0 || screen->windowOffsetY != 0) && - !windowOnAllViewports (w)) + if ((windowOffsetX != 0 || windowOffsetY != 0) && + !w->onAllViewports ()) { - getWindowMovementForOffset (w, screen->windowOffsetX, - screen->windowOffsetY, &offX, &offY); + w->getMovementForOffset (windowOffsetX, + windowOffsetY, &offX, &offY); vTransform = *transform; matrixTranslate (&vTransform, offX, offY, 0); - (*screen->paintWindow) (w, &w->paint, &vTransform, clip, - windowMask | PAINT_WINDOW_WITH_OFFSET_MASK); + w->paint (&w->paintAttrib (), &vTransform, clip, + windowMask | PAINT_WINDOW_WITH_OFFSET_MASK); } else { - (*screen->paintWindow) (w, &w->paint, transform, clip, - windowMask); + w->paint (&w->paintAttrib (), transform, clip, windowMask); } } @@ -410,17 +409,18 @@ paintOutputRegion (CompScreen *screen, (*walk.fini) (screen, &walk); /* paint cursors */ - for (c = screen->cursors; c; c = c->next) - (*screen->paintCursor) (c, transform, tmpRegion, 0); + for (c = cursors; c; c = c->next) + screen->paintCursor (c, transform, tmpRegion, 0); } void -enableOutputClipping (CompScreen *screen, - const CompTransform *transform, - Region region, - CompOutput *output) +CompScreen::enableOutputClipping (const CompTransform *transform, + Region region, + CompOutput *output) { - GLdouble h = screen->height; + WRAPABLE_HND_FUNC(enableOutputClipping, transform, region, output) + + GLdouble h = priv->height; GLdouble p1[2] = { region->extents.x1, h - region->extents.y2 }; GLdouble p2[2] = { region->extents.x2, h - region->extents.y1 }; @@ -453,8 +453,10 @@ enableOutputClipping (CompScreen *screen, } void -disableOutputClipping (CompScreen *screen) +CompScreen::disableOutputClipping () { + WRAPABLE_HND_FUNC(disableOutputClipping) + glDisable (GL_CLIP_PLANE0); glDisable (GL_CLIP_PLANE1); glDisable (GL_CLIP_PLANE2); @@ -465,60 +467,64 @@ disableOutputClipping (CompScreen *screen) PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK) void -paintTransformedOutput (CompScreen *screen, - const ScreenPaintAttrib *sAttrib, - const CompTransform *transform, - Region region, - CompOutput *output, - unsigned int mask) +CompScreen::paintTransformedOutput (const ScreenPaintAttrib *sAttrib, + const CompTransform *transform, + Region region, + CompOutput *output, + unsigned int mask) { + WRAPABLE_HND_FUNC(paintTransformedOutput, sAttrib, transform, + region, output, mask) + CompTransform sTransform = *transform; if (mask & PAINT_SCREEN_CLEAR_MASK) - clearTargetOutput (screen->display, GL_COLOR_BUFFER_BIT); + priv->display->clearTargetOutput (GL_COLOR_BUFFER_BIT); - screenLighting (screen, TRUE); + setLighting (true); - (*screen->applyScreenTransform) (screen, sAttrib, output, &sTransform); + applyTransform (sAttrib, output, &sTransform); if ((mask & CLIP_PLANE_MASK) == CLIP_PLANE_MASK) { - screen->enableOutputClipping (screen, &sTransform, region, output); + enableOutputClipping (&sTransform, region, output); - transformToScreenSpace (screen, output, -sAttrib->zTranslate, + transformToScreenSpace (this, output, -sAttrib->zTranslate, &sTransform); glPushMatrix (); glLoadMatrixf (sTransform.m); - paintOutputRegion (screen, &sTransform, region, output, mask); + priv->paintOutputRegion (&sTransform, region, output, mask); glPopMatrix (); - screen->disableOutputClipping (screen); + disableOutputClipping (); } else { - transformToScreenSpace (screen, output, -sAttrib->zTranslate, + transformToScreenSpace (this, output, -sAttrib->zTranslate, &sTransform); glPushMatrix (); glLoadMatrixf (sTransform.m); - paintOutputRegion (screen, &sTransform, region, output, mask); + priv->paintOutputRegion (&sTransform, region, output, mask); glPopMatrix (); } } -Bool -paintOutput (CompScreen *screen, - const ScreenPaintAttrib *sAttrib, - const CompTransform *transform, - Region region, - CompOutput *output, - unsigned int mask) +bool +CompScreen::paintOutput (const ScreenPaintAttrib *sAttrib, + const CompTransform *transform, + Region region, + CompOutput *output, + unsigned int mask) { + WRAPABLE_HND_FUNC_RETURN(bool, paintOutput, sAttrib, transform, + region, output, mask) + CompTransform sTransform = *transform; if (mask & PAINT_SCREEN_REGION_MASK) @@ -529,41 +535,39 @@ paintOutput (CompScreen *screen, { region = &output->region; - (*screen->paintTransformedOutput) (screen, sAttrib, - &sTransform, region, - output, mask); + paintTransformedOutput (sAttrib, &sTransform, region, + output, mask); - return TRUE; + return true; } - return FALSE; + return false; } /* fall through and redraw region */ } else if (mask & PAINT_SCREEN_FULL_MASK) { - (*screen->paintTransformedOutput) (screen, sAttrib, &sTransform, - &output->region, - output, mask); + paintTransformedOutput (sAttrib, &sTransform, &output->region, + output, mask); - return TRUE; + return true; } else - return FALSE; + return false; - screenLighting (screen, FALSE); + setLighting (false); - transformToScreenSpace (screen, output, -DEFAULT_Z_CAMERA, &sTransform); + transformToScreenSpace (this, output, -DEFAULT_Z_CAMERA, &sTransform); glPushMatrix (); glLoadMatrixf (sTransform.m); - paintOutputRegion (screen, &sTransform, region, output, mask); + priv->paintOutputRegion (&sTransform, region, output, mask); glPopMatrix (); - return TRUE; + return true; } #define ADD_RECT(data, m, n, x1, y1, x2, y2) \ @@ -635,51 +639,53 @@ paintOutput (CompScreen *screen, *(data)++ = 0.0; -Bool -moreWindowVertices (CompWindow *w, - int newSize) +bool +CompWindow::moreVertices (int newSize) { - if (newSize > w->vertexSize) + if (newSize > priv->vertexSize) { GLfloat *vertices; - vertices = (GLfloat *) realloc (w->vertices, sizeof (GLfloat) * newSize); + vertices = (GLfloat *) + realloc (priv->vertices, sizeof (GLfloat) * newSize); if (!vertices) - return FALSE; + return false; - w->vertices = vertices; - w->vertexSize = newSize; + priv->vertices = vertices; + priv->vertexSize = newSize; } - return TRUE; + return true; } -Bool -moreWindowIndices (CompWindow *w, - int newSize) +bool +CompWindow::moreIndices (int newSize) { - if (newSize > w->indexSize) + if (newSize > priv->indexSize) { GLushort *indices; - indices = (GLushort *) realloc (w->indices, sizeof (GLushort) * newSize); + indices = (GLushort *) + realloc (priv->indices, sizeof (GLushort) * newSize); if (!indices) - return FALSE; + return false; - w->indices = indices; - w->indexSize = newSize; + priv->indices = indices; + priv->indexSize = newSize; } - return TRUE; + return true; } -static void -drawWindowGeometry (CompWindow *w) +void +CompWindow::drawGeometry () { - int texUnit = w->texUnits; + WRAPABLE_HND_FUNC(drawGeometry) + + int texUnit = priv->texUnits; int currentTexUnit = 0; - int stride = w->vertexStride; - GLfloat *vertices = w->vertices + (stride - 3); + int stride = priv->vertexStride; + GLfloat *vertices = priv->vertices + (stride - 3); stride *= sizeof (GLfloat); @@ -689,40 +695,41 @@ drawWindowGeometry (CompWindow *w) { if (texUnit != currentTexUnit) { - (*w->screen->clientActiveTexture) (GL_TEXTURE0_ARB + texUnit); + (*priv->screen->clientActiveTexture) (GL_TEXTURE0_ARB + texUnit); glEnableClientState (GL_TEXTURE_COORD_ARRAY); currentTexUnit = texUnit; } - vertices -= w->texCoordSize; - glTexCoordPointer (w->texCoordSize, GL_FLOAT, stride, vertices); + vertices -= priv->texCoordSize; + glTexCoordPointer (priv->texCoordSize, GL_FLOAT, stride, vertices); } - glDrawArrays (GL_QUADS, 0, w->vCount); + glDrawArrays (GL_QUADS, 0, priv->vCount); /* disable all texture coordinate arrays except 0 */ - texUnit = w->texUnits; + texUnit = priv->texUnits; if (texUnit > 1) { while (--texUnit) { - (*w->screen->clientActiveTexture) (GL_TEXTURE0_ARB + texUnit); + (*priv->screen->clientActiveTexture) (GL_TEXTURE0_ARB + texUnit); glDisableClientState (GL_TEXTURE_COORD_ARRAY); } - (*w->screen->clientActiveTexture) (GL_TEXTURE0_ARB); + (*priv->screen->clientActiveTexture) (GL_TEXTURE0_ARB); } } void -addWindowGeometry (CompWindow *w, - CompMatrix *matrix, - int nMatrix, - Region region, - Region clip) +CompWindow::addGeometry (CompMatrix *matrix, + int nMatrix, + Region region, + Region clip) { + WRAPABLE_HND_FUNC(addGeometry, matrix, nMatrix, region, clip) + BoxRec full; - w->texUnits = nMatrix; + priv->texUnits = nMatrix; full = clip->extents; if (region->extents.x1 > full.x1) @@ -744,13 +751,13 @@ addWindowGeometry (CompWindow *w, int vSize; int n, it, x1, y1, x2, y2; GLfloat *d; - Bool rect = TRUE; + bool rect = true; for (it = 0; it < nMatrix; it++) { if (matrix[it].xy != 0.0f || matrix[it].yx != 0.0f) { - rect = FALSE; + rect = false; break; } } @@ -760,15 +767,15 @@ addWindowGeometry (CompWindow *w, vSize = 3 + nMatrix * 2; - n = w->vCount / 4; + n = priv->vCount / 4; - if ((n + nBox) * vSize * 4 > w->vertexSize) + if ((n + nBox) * vSize * 4 > priv->vertexSize) { - if (!moreWindowVertices (w, (n + nBox) * vSize * 4)) + if (!moreVertices ((n + nBox) * vSize * 4)) return; } - d = w->vertices + (w->vCount * vSize); + d = priv->vertices + (priv->vCount * vSize); while (nBox--) { @@ -809,12 +816,12 @@ addWindowGeometry (CompWindow *w, { pClip = clip->rects; - if (((n + nClip) * vSize * 4) > w->vertexSize) + if (((n + nClip) * vSize * 4) > priv->vertexSize) { - if (!moreWindowVertices (w, (n + nClip) * vSize * 4)) + if (!moreVertices ((n + nClip) * vSize * 4)) return; - d = w->vertices + (n * vSize * 4); + d = priv->vertices + (n * vSize * 4); } while (nClip--) @@ -852,14 +859,13 @@ addWindowGeometry (CompWindow *w, } } - w->vCount = n * 4; - w->vertexStride = vSize; - w->texCoordSize = 2; - w->drawWindowGeometry = drawWindowGeometry; + priv->vCount = n * 4; + priv->vertexStride = vSize; + priv->texCoordSize = 2; } } -static Bool +static bool enableFragmentProgramAndDrawGeometry (CompWindow *w, CompTexture *texture, const FragmentAttrib *attrib, @@ -867,10 +873,10 @@ enableFragmentProgramAndDrawGeometry (CompWindow *w, unsigned int mask) { FragmentAttrib fa = *attrib; - CompScreen *s = w->screen; + CompScreen *s = w->screen (); Bool blending; - if (s->canDoSaturated && attrib->saturation != COLOR) + if (s->canDoSaturated () && attrib->saturation != COLOR) { int param, function; @@ -887,9 +893,9 @@ enableFragmentProgramAndDrawGeometry (CompWindow *w, } if (!enableFragmentAttrib (s, &fa, &blending)) - return FALSE; + return false; - enableTexture (s, texture, filter); + s->enableTexture (texture, filter); if (mask & PAINT_WINDOW_BLEND_MASK) { @@ -902,17 +908,17 @@ enableFragmentProgramAndDrawGeometry (CompWindow *w, color = (attrib->opacity * attrib->brightness) >> 16; - screenTexEnvMode (s, GL_MODULATE); + s->setTexEnvMode (GL_MODULATE); glColor4us (color, color, color, attrib->opacity); - (*w->drawWindowGeometry) (w); + w->drawGeometry (); glColor4usv (defaultColor); - screenTexEnvMode (s, GL_REPLACE); + s->setTexEnvMode (GL_REPLACE); } else { - (*w->drawWindowGeometry) (w); + w->drawGeometry (); } if (blending) @@ -920,25 +926,25 @@ enableFragmentProgramAndDrawGeometry (CompWindow *w, } else if (attrib->brightness != BRIGHT) { - screenTexEnvMode (s, GL_MODULATE); + s->setTexEnvMode (GL_MODULATE); glColor4us (attrib->brightness, attrib->brightness, attrib->brightness, BRIGHT); - (*w->drawWindowGeometry) (w); + w->drawGeometry (); glColor4usv (defaultColor); - screenTexEnvMode (s, GL_REPLACE); + s->setTexEnvMode (GL_REPLACE); } else { - (*w->drawWindowGeometry) (w); + w->drawGeometry (); } - disableTexture (w->screen, texture); + s->disableTexture (texture); disableFragmentAttrib (s, &fa); - return TRUE; + return true; } static void @@ -948,16 +954,16 @@ enableFragmentOperationsAndDrawGeometry (CompWindow *w, int filter, unsigned int mask) { - CompScreen *s = w->screen; + CompScreen *s = w->screen (); - if (s->canDoSaturated && attrib->saturation != COLOR) + if (s->canDoSaturated () && attrib->saturation != COLOR) { GLfloat constant[4]; if (mask & PAINT_WINDOW_BLEND_MASK) glEnable (GL_BLEND); - enableTexture (s, texture, filter); + s->enableTexture (texture, filter); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); @@ -977,7 +983,7 @@ enableFragmentOperationsAndDrawGeometry (CompWindow *w, s->activeTexture (GL_TEXTURE1_ARB); - enableTexture (s, texture, filter); + s->enableTexture (texture, filter); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); @@ -987,7 +993,7 @@ enableFragmentOperationsAndDrawGeometry (CompWindow *w, glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); - if (s->canDoSlightlySaturated && attrib->saturation > 0) + if (s->canDoSlightlySaturated () && attrib->saturation > 0) { glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); @@ -1002,7 +1008,7 @@ enableFragmentOperationsAndDrawGeometry (CompWindow *w, s->activeTexture (GL_TEXTURE2_ARB); - enableTexture (s, texture, filter); + s->enableTexture (texture, filter); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); @@ -1026,7 +1032,7 @@ enableFragmentOperationsAndDrawGeometry (CompWindow *w, { s->activeTexture (GL_TEXTURE3_ARB); - enableTexture (s, texture, filter); + s->enableTexture (texture, filter); constant[3] = attrib->opacity / 65535.0f; constant[0] = constant[1] = constant[2] = constant[3] * @@ -1048,9 +1054,9 @@ enableFragmentOperationsAndDrawGeometry (CompWindow *w, glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA); - (*w->drawWindowGeometry) (w); + w->drawGeometry (); - disableTexture (s, texture); + s->disableTexture (texture); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); @@ -1058,10 +1064,10 @@ enableFragmentOperationsAndDrawGeometry (CompWindow *w, } else { - (*w->drawWindowGeometry) (w); + w->drawGeometry (); } - disableTexture (s, texture); + s->disableTexture (texture); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); @@ -1085,26 +1091,26 @@ enableFragmentOperationsAndDrawGeometry (CompWindow *w, glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constant); - (*w->drawWindowGeometry) (w); + w->drawGeometry (); } - disableTexture (s, texture); + s->disableTexture (texture); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); s->activeTexture (GL_TEXTURE0_ARB); - disableTexture (s, texture); + s->disableTexture (texture); glColor4usv (defaultColor); - screenTexEnvMode (s, GL_REPLACE); + s->setTexEnvMode (GL_REPLACE); if (mask & PAINT_WINDOW_BLEND_MASK) glDisable (GL_BLEND); } else { - enableTexture (s, texture, filter); + s->enableTexture (texture, filter); if (mask & PAINT_WINDOW_BLEND_MASK) { @@ -1115,64 +1121,65 @@ enableFragmentOperationsAndDrawGeometry (CompWindow *w, color = (attrib->opacity * attrib->brightness) >> 16; - screenTexEnvMode (s, GL_MODULATE); + s->setTexEnvMode (GL_MODULATE); glColor4us (color, color, color, attrib->opacity); - (*w->drawWindowGeometry) (w); + w->drawGeometry (); glColor4usv (defaultColor); - screenTexEnvMode (s, GL_REPLACE); + s->setTexEnvMode (GL_REPLACE); } else { - (*w->drawWindowGeometry) (w); + w->drawGeometry (); } glDisable (GL_BLEND); } else if (attrib->brightness != BRIGHT) { - screenTexEnvMode (s, GL_MODULATE); + s->setTexEnvMode (GL_MODULATE); glColor4us (attrib->brightness, attrib->brightness, attrib->brightness, BRIGHT); - (*w->drawWindowGeometry) (w); + w->drawGeometry (); glColor4usv (defaultColor); - screenTexEnvMode (s, GL_REPLACE); + s->setTexEnvMode (GL_REPLACE); } else { - (*w->drawWindowGeometry) (w); + w->drawGeometry (); } - disableTexture (w->screen, texture); + s->disableTexture (texture); } } void -drawWindowTexture (CompWindow *w, - CompTexture *texture, - const FragmentAttrib *attrib, - unsigned int mask) +CompWindow::drawTexture (CompTexture *texture, + const FragmentAttrib *attrib, + unsigned int mask) { + WRAPABLE_HND_FUNC(drawTexture, texture, attrib, mask) + int filter; if (mask & (PAINT_WINDOW_TRANSFORMED_MASK | PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK)) - filter = w->screen->filter[SCREEN_TRANS_FILTER]; + filter = priv->screen->filter (SCREEN_TRANS_FILTER); else - filter = w->screen->filter[NOTHING_TRANS_FILTER]; + filter = priv->screen->filter (NOTHING_TRANS_FILTER); - if ((!attrib->nFunction && (!w->screen->lighting || + if ((!attrib->nFunction && (!priv->screen->lighting () || attrib->saturation == COLOR || attrib->saturation == 0)) || - !enableFragmentProgramAndDrawGeometry (w, + !enableFragmentProgramAndDrawGeometry (this, texture, attrib, filter, mask)) { - enableFragmentOperationsAndDrawGeometry (w, + enableFragmentOperationsAndDrawGeometry (this, texture, attrib, filter, @@ -1180,72 +1187,74 @@ drawWindowTexture (CompWindow *w, } } -Bool -drawWindow (CompWindow *w, - const CompTransform *transform, - const FragmentAttrib *fragment, - Region region, - unsigned int mask) +bool +CompWindow::draw (const CompTransform *transform, + const FragmentAttrib *fragment, + Region region, + unsigned int mask) { + WRAPABLE_HND_FUNC_RETURN(bool, draw, transform, fragment, region, mask) + if (mask & PAINT_WINDOW_TRANSFORMED_MASK) region = &infiniteRegion; if (!region->numRects) - return TRUE; + return true; - if (w->attrib.map_state != IsViewable) - return TRUE; + if (priv->attrib.map_state != IsViewable) + return true; - if (!w->texture->pixmap && !bindWindow (w)) - return FALSE; + if (!priv->texture->pixmap && !bind ()) + return false; if (mask & PAINT_WINDOW_TRANSLUCENT_MASK) mask |= PAINT_WINDOW_BLEND_MASK; - w->vCount = w->indexCount = 0; - (*w->screen->addWindowGeometry) (w, &w->matrix, 1, w->region, region); - if (w->vCount) - (*w->screen->drawWindowTexture) (w, w->texture, fragment, mask); + priv->vCount = priv->indexCount = 0; + addGeometry (&priv->matrix, 1, priv->region, region); + if (priv->vCount) + drawTexture (priv->texture, fragment, mask); - return TRUE; + return true; } -Bool -paintWindow (CompWindow *w, - const WindowPaintAttrib *attrib, - const CompTransform *transform, - Region region, - unsigned int mask) +bool +CompWindow::paint (const WindowPaintAttrib *attrib, + const CompTransform *transform, + Region region, + unsigned int mask) { + WRAPABLE_HND_FUNC_RETURN(bool, paint, attrib, transform, region, mask) + FragmentAttrib fragment; Bool status; - w->lastPaint = *attrib; + priv->lastPaint = *attrib; - if (w->alpha || attrib->opacity != OPAQUE) + if (priv->alpha || attrib->opacity != OPAQUE) mask |= PAINT_WINDOW_TRANSLUCENT_MASK; - w->lastMask = mask; + priv->lastMask = mask; if (mask & PAINT_WINDOW_OCCLUSION_DETECTION_MASK) { if (mask & PAINT_WINDOW_TRANSFORMED_MASK) - return FALSE; + return false; if (mask & PAINT_WINDOW_NO_CORE_INSTANCE_MASK) - return FALSE; + return false; if (mask & PAINT_WINDOW_TRANSLUCENT_MASK) - return FALSE; + return false; - if (w->shaded) - return FALSE; + if (priv->shaded) + return false; - return TRUE; + return true; } if (mask & PAINT_WINDOW_NO_CORE_INSTANCE_MASK) - return TRUE; + return true; initFragmentAttrib (&fragment, attrib); @@ -1256,7 +1265,7 @@ paintWindow (CompWindow *w, glLoadMatrixf (transform->m); } - status = (*w->screen->drawWindow) (w, transform, &fragment, region, mask); + status = draw (transform, &fragment, region, mask); if (mask & PAINT_WINDOW_TRANSFORMED_MASK || mask & PAINT_WINDOW_WITH_OFFSET_MASK) diff --git a/src/plugin.cpp b/src/plugin.cpp index d545240..d81b320 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -33,43 +33,66 @@ CompPlugin *plugins = 0; -static Bool -coreInit (CompPlugin *p) +class CorePluginVTable : public CompPluginVTable { - return TRUE; + public: + + const char * + name () { return "core"; }; + + CompMetadata * + getMetadata (); + + virtual bool + init (); + + virtual void + fini (); + + CompOption * + getObjectOptions (CompObject *object, int *count); + + bool + setObjectOption (CompObject *object, + const char *name, + CompOptionValue *value); +}; + +bool +CorePluginVTable::init () +{ + return true; } -static void -coreFini (CompPlugin *p) +void +CorePluginVTable::fini () { } -static CompMetadata * -coreGetMetadata (CompPlugin *plugin) +CompMetadata * +CorePluginVTable::getMetadata () { return &coreMetadata; } -static CompOption * -coreGetObjectOptions (CompPlugin *plugin, - CompObject *object, - int *count) +CompOption * +CorePluginVTable::getObjectOptions (CompObject *object, + int *count) { static GetPluginObjectOptionsProc dispTab[] = { (GetPluginObjectOptionsProc) 0, /* GetCoreOptions */ - (GetPluginObjectOptionsProc) getDisplayOptions, - (GetPluginObjectOptionsProc) getScreenOptions + (GetPluginObjectOptionsProc) CompDisplay::getDisplayOptions, + (GetPluginObjectOptionsProc) CompScreen::getScreenOptions }; RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab), - (CompOption *) (*count = 0), (plugin, object, count)); + (CompOption *) (*count = 0), (object, count)); } -static Bool -coreSetObjectOption (CompPlugin *plugin, - CompObject *object, - const char *name, - CompOptionValue *value) +bool +CorePluginVTable::setObjectOption (CompObject *object, + const char *name, + CompOptionValue *value) { static SetPluginObjectOptionProc dispTab[] = { (SetPluginObjectOptionProc) 0, /* SetCoreOption */ @@ -78,19 +101,12 @@ coreSetObjectOption (CompPlugin *plugin, }; RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab), FALSE, - (plugin, object, name, value)); -} - -static CompPluginVTable coreVTable = { - "core", - coreGetMetadata, - coreInit, - coreFini, - 0, /* InitObject */ - 0, /* FiniObject */ - coreGetObjectOptions, - coreSetObjectOption -}; + (object, name, value)); +} + + + +CorePluginVTable coreVTable; static Bool cloaderLoadPlugin (CompPlugin *p, @@ -100,7 +116,7 @@ cloaderLoadPlugin (CompPlugin *p, if (path) return FALSE; - if (strcmp (name, coreVTable.name)) + if (strcmp (name, coreVTable.name ())) return FALSE; p->vTable = &coreVTable; @@ -128,7 +144,7 @@ cloaderListPlugins (const char *path, if (!list) return 0; - *list = strdup (coreVTable.name); + *list = strdup (coreVTable.name ()); if (!*list) { free (list); @@ -166,7 +182,7 @@ dlloaderLoadPlugin (CompPlugin *p, dlerror (); getInfo = (PluginGetInfoProc) - dlsym (dlhand, "getCompPluginInfo20070830"); + dlsym (dlhand, "getCompPluginInfo20080805"); error = dlerror (); if (error) @@ -364,14 +380,12 @@ initObjectTree (CompObject *object, pCtx->object = object; - if (p->vTable->initObject) + + if (!p->vTable->initObject (object)) { - if (!(*p->vTable->initObject) (p, object)) - { - compLogMessage (NULL, p->vTable->name, CompLogLevelError, - "InitObject failed"); - return FALSE; - } + compLogMessage (NULL, p->vTable->name (), CompLogLevelError, + "InitObject failed"); + return FALSE; } ctx.plugin = p; @@ -382,18 +396,16 @@ initObjectTree (CompObject *object, { compObjectForEachType (object, finiObjectsWithType, (void *) &ctx); - if (p->vTable->initObject && p->vTable->finiObject) - (*p->vTable->finiObject) (p, object); + p->vTable->finiObject (object); return FALSE; } - if (!(*core.initPluginForObject) (p, object)) + if (!core->initPluginForObject (p, object)) { compObjectForEachType (object, finiObjectsWithType, (void *) &ctx); - if (p->vTable->initObject && p->vTable->finiObject) - (*p->vTable->finiObject) (p, object); + p->vTable->finiObject (object); return FALSE; } @@ -418,10 +430,10 @@ finiObjectTree (CompObject *object, compObjectForEachType (object, finiObjectsWithType, (void *) &ctx); - if (p->vTable->initObject && p->vTable->finiObject) - (*p->vTable->finiObject) (p, object); + + p->vTable->finiObject (object); - (*core.finiPluginForObject) (p, object); + core->finiPluginForObject (p, object); return TRUE; } @@ -431,19 +443,19 @@ initPlugin (CompPlugin *p) { InitObjectContext ctx; - if (!(*p->vTable->init) (p)) + if (!p->vTable->init ()) { compLogMessage (NULL, "core", CompLogLevelError, - "InitPlugin '%s' failed", p->vTable->name); + "InitPlugin '%s' failed", p->vTable->name ()); return FALSE; } ctx.plugin = p; ctx.object = NULL; - if (!initObjectTree (&core.base, (void *) &ctx)) + if (!initObjectTree (core, (void *) &ctx)) { - (*p->vTable->fini) (p); + p->vTable->fini (); return FALSE; } @@ -458,9 +470,9 @@ finiPlugin (CompPlugin *p) ctx.plugin = p; ctx.object = NULL; - finiObjectTree (&core.base, (void *) &ctx); + finiObjectTree (core, (void *) &ctx); - (*p->vTable->fini) (p); + p->vTable->fini (); } CompBool @@ -522,7 +534,7 @@ findActivePlugin (const char *name) for (p = plugins; p; p = p->next) { - if (strcmp (p->vTable->name, name) == 0) + if (strcmp (p->vTable->name (), name) == 0) return p; } @@ -584,11 +596,11 @@ loadPlugin (const char *name) Bool pushPlugin (CompPlugin *p) { - if (findActivePlugin (p->vTable->name)) + if (findActivePlugin (p->vTable->name ())) { compLogMessage (NULL, "core", CompLogLevelWarn, "Plugin '%s' already active", - p->vTable->name); + p->vTable->name ()); return FALSE; } @@ -599,7 +611,7 @@ pushPlugin (CompPlugin *p) if (!initPlugin (p)) { compLogMessage (NULL, "core", CompLogLevelError, - "Couldn't activate plugin '%s'", p->vTable->name); + "Couldn't activate plugin '%s'", p->vTable->name ()); plugins = p->next; return FALSE; @@ -721,11 +733,11 @@ getPluginABI (const char *name) CompOption *option; int nOption; - if (!p || !p->vTable->getObjectOptions) + if (!p) return 0; /* MULTIDPYERROR: ABI options should be moved into core */ - option = (*p->vTable->getObjectOptions) (p, &core.displays->base, + option = p->vTable->getObjectOptions (core->displays(), &nOption); return getIntOptionNamed (option, nOption, "abi", 0); @@ -765,10 +777,10 @@ getPluginDisplayIndex (CompDisplay *d, CompOption *option; int nOption, value; - if (!p || !p->vTable->getObjectOptions) + if (!p) return FALSE; - option = (*p->vTable->getObjectOptions) (p, &d->base, &nOption); + option = p->vTable->getObjectOptions (d, &nOption); value = getIntOptionNamed (option, nOption, "index", -1); if (value < 0) @@ -778,3 +790,41 @@ getPluginDisplayIndex (CompDisplay *d, return TRUE; } + + +CompPluginVTable::~CompPluginVTable () +{ +} + +CompMetadata * +CompPluginVTable::getMetadata () +{ + return NULL; +} + + +bool +CompPluginVTable::initObject (CompObject *object) +{ + return true; +} + +void +CompPluginVTable::finiObject (CompObject *object) +{ +} + +CompOption * +CompPluginVTable::getObjectOptions (CompObject *object, int *count) +{ + (*count) = 0; + return NULL; +} + +bool +CompPluginVTable::setObjectOption (CompObject *object, + const char *name, + CompOptionValue *value) +{ + return false; +} diff --git a/src/privatecore.h b/src/privatecore.h new file mode 100644 index 0000000..c6b4764 --- /dev/null +++ b/src/privatecore.h @@ -0,0 +1,42 @@ +#ifndef _PRIVATECORE_H +#define _PRIVATECORE_H + +#include <compiz-core.h> +#include <compcore.h> + +class PrivateCore { + + public: + PrivateCore (CompCore *core); + ~PrivateCore (); + + void + addTimeout(CompTimeout *); + + short int + watchFdEvents (CompWatchFdHandle handle); + + int + doPoll (int timeout); + + void + handleTimeouts (struct timeval *tv); + + public: + CompCore *core; + CompDisplay *displays; + + std::list<CompFileWatch *> fileWatch; + CompFileWatchHandle lastFileWatchHandle; + + std::list<CompTimeout *> timeouts; + struct timeval lastTimeout; + CompTimeoutHandle lastTimeoutHandle; + + std::list<CompWatchFd *> watchFds; + CompWatchFdHandle lastWatchFdHandle; + struct pollfd *watchPollFds; + int nWatchFds; +}; + +#endif diff --git a/src/privatedisplay.h b/src/privatedisplay.h new file mode 100644 index 0000000..7068f45 --- /dev/null +++ b/src/privatedisplay.h @@ -0,0 +1,138 @@ +#ifndef _PRIVATEDISPLAY_H +#define _PRIVATEDISPLAY_H + +#include <compiz-core.h> +#include <compdisplay.h> + +class PrivateDisplay { + + public: + PrivateDisplay (CompDisplay *display); + ~PrivateDisplay (); + + void + updatePlugins (); + + bool + triggerButtonPressBindings (CompOption *option, + int nOption, + XEvent *event, + CompOption *argument, + int nArgument); + + bool + triggerButtonReleaseBindings (CompOption *option, + int nOption, + XEvent *event, + CompOption *argument, + int nArgument); + + bool + triggerKeyPressBindings (CompOption *option, + int nOption, + XEvent *event, + CompOption *argument, + int nArgument); + + bool + triggerKeyReleaseBindings (CompOption *option, + int nOption, + XEvent *event, + CompOption *argument, + int nArgument); + + bool + triggerStateNotifyBindings (CompOption *option, + int nOption, + XkbStateNotifyEvent *event, + CompOption *argument, + int nArgument); + + bool + triggerEdgeEnter (unsigned int edge, + CompActionState state, + CompOption *argument, + unsigned int nArgument); + + void + setAudibleBell (bool audible); + + void + handlePingTimeout (); + + bool + handleActionEvent (XEvent *event); + + void + handleSelectionRequest (XEvent *event); + + void + handleSelectionClear (XEvent *event); + + void + initAtoms (); + + public: + + CompDisplay *display; + + xcb_connection_t *connection; + + Display *dpy; + CompScreen *screens; + + CompWatchFdHandle watchFdHandle; + + int compositeEvent, compositeError, compositeOpcode; + int damageEvent, damageError; + int syncEvent, syncError; + int fixesEvent, fixesError, fixesVersion; + + bool randrExtension; + int randrEvent, randrError; + + bool shapeExtension; + int shapeEvent, shapeError; + + bool xkbExtension; + int xkbEvent, xkbError; + + bool xineramaExtension; + int xineramaEvent, xineramaError; + + XineramaScreenInfo *screenInfo; + int nScreenInfo; + + SnDisplay *snDisplay; + + unsigned int lastPing; + CompTimeoutHandle pingHandle; + + GLenum textureFilter; + + Window activeWindow; + + Window below; + char displayString[256]; + + XModifierKeymap *modMap; + unsigned int modMask[CompModNum]; + unsigned int ignoredModMask; + + KeyCode escapeKeyCode; + KeyCode returnKeyCode; + + CompOption opt[COMP_DISPLAY_OPTION_NUM]; + + CompTimeoutHandle autoRaiseHandle; + Window autoRaiseWindow; + + CompTimeoutHandle edgeDelayHandle; + + CompOptionValue plugin; + bool dirtyPluginList; + + CompDisplay::Atoms atoms; +}; + +#endif diff --git a/src/privatescreen.h b/src/privatescreen.h new file mode 100644 index 0000000..a0dabc6 --- /dev/null +++ b/src/privatescreen.h @@ -0,0 +1,251 @@ +#ifndef _PRIVATESCREEN_H +#define _PRIVATESCREEN_H + +#include <compiz-core.h> +#include <compscreen.h> + +class PrivateScreen { + + public: + PrivateScreen (CompScreen *screen); + ~PrivateScreen (); + + bool + desktopHintEqual (unsigned long *data, + int size, + int offset, + int hintSize); + + void + setDesktopHints (); + + void + setVirtualScreenSize (int hsize, int vsize); + + void + updateOutputDevices (); + + void + detectOutputDevices (); + + void + updateStartupFeedback (); + + void + updateScreenEdges (); + + void + reshape (int w, int h); + + void + updateScreenBackground (CompTexture *texture); + + void + handleStartupSequenceTimeout(); + + void + addSequence (SnStartupSequence *sequence); + + void + removeSequence (SnStartupSequence *sequence); + + void + setSupportingWmCheck (); + + void + setSupported (); + + void + getDesktopHints (); + + void + makeOutputWindow (); + + void + grabUngrabOneKey (unsigned int modifiers, + int keycode, + bool grab); + + + bool + grabUngrabKeys (unsigned int modifiers, + int keycode, + bool grab); + + bool + addPassiveKeyGrab (CompKeyBinding *key); + + void + removePassiveKeyGrab (CompKeyBinding *key); + + void + updatePassiveKeyGrabs (); + + bool + addPassiveButtonGrab (CompButtonBinding *button); + + void + removePassiveButtonGrab (CompButtonBinding *button); + + void + computeWorkareaForBox (BoxPtr pBox, XRectangle *area); + + void + paintBackground (Region region, + bool transformed); + + void + paintOutputRegion (const CompTransform *transform, + Region region, + CompOutput *output, + unsigned int mask); + + static bool + paintTimeout (void *closure); + + public: + + CompScreen *screen; + CompDisplay *display; + CompWindow *windows; + CompWindow *reverseWindows; + + + Colormap colormap; + int screenNum; + int width; + int height; + int x; + int y; + int hsize; /* Number of horizontal viewports */ + int vsize; /* Number of vertical viewports */ + unsigned int nDesktop; + unsigned int currentDesktop; + REGION region; + Region damage; + unsigned long damageMask; + Window root; + Window overlay; + Window output; + XWindowAttributes attrib; + Window grabWindow; + CompFBConfig glxPixmapFBConfigs[MAX_DEPTH + 1]; + int textureRectangle; + int textureNonPowerOfTwo; + int textureEnvCombine; + int textureEnvCrossbar; + int textureBorderClamp; + int textureCompression; + GLint maxTextureSize; + int fbo; + int fragmentProgram; + int maxTextureUnits; + Cursor invisibleCursor; + XRectangle *exposeRects; + int sizeExpose; + int nExpose; + CompTexture backgroundTexture; + Bool backgroundLoaded; + unsigned int pendingDestroys; + int desktopWindowCount; + unsigned int mapNum; + unsigned int activeNum; + + CompOutput *outputDev; + int nOutputDev; + int currentOutputDev; + CompOutput fullscreenOutput; + Bool hasOverlappingOutputs; + + int windowOffsetX; + int windowOffsetY; + + XRectangle lastViewport; + + CompActiveWindowHistory history[ACTIVE_WINDOW_HISTORY_NUM]; + int currentHistory; + + int overlayWindowCount; + + CompScreenEdge screenEdge[SCREEN_EDGE_NUM]; + + SnMonitorContext *snContext; + CompStartupSequence *startupSequences; + unsigned int startupSequenceTimeoutHandle; + + int filter[3]; + + CompGroup *groups; + + CompIcon *defaultIcon; + + Bool canDoSaturated; + Bool canDoSlightlySaturated; + + Window wmSnSelectionWindow; + Atom wmSnAtom; + Time wmSnTimestamp; + + Cursor normalCursor; + Cursor busyCursor; + + CompWindow **clientList; + int nClientList; + + CompButtonGrab *buttonGrab; + int nButtonGrab; + CompKeyGrab *keyGrab; + int nKeyGrab; + + CompGrab *grabs; + int grabSize; + int maxGrab; + + int rasterX; + int rasterY; + struct timeval lastRedraw; + int nextRedraw; + int redrawTime; + int optimalRedrawTime; + int frameStatus; + int timeMult; + Bool idle; + int timeLeft; + Bool pendingCommands; + + int lastFunctionId; + + CompFunction *fragmentFunctions; + CompProgram *fragmentPrograms; + + int saturateFunction[2][64]; + + GLfloat projection[16]; + + Bool clearBuffers; + + Bool lighting; + Bool slowAnimations; + + XRectangle workArea; + + unsigned int showingDesktopMask; + + unsigned long *desktopHintData; + int desktopHintSize; + + CompCursor *cursors; + CompCursorImage *cursorImages; + + GLXContext ctx; + + CompOption opt[COMP_SCREEN_OPTION_NUM]; + + + CompTimeoutHandle paintHandle; + + GLXGetProcAddressProc getProcAddress; + +}; + +#endif diff --git a/src/privatewindow.h b/src/privatewindow.h new file mode 100644 index 0000000..0befa96 --- /dev/null +++ b/src/privatewindow.h @@ -0,0 +1,269 @@ +#ifndef _PRIVATEWINDOW_H +#define _PRIVATEWINDOW_H + +#include <compiz-core.h> +#include <compwindow.h> + +#define WINDOW_INVISIBLE(w) \ + ((w)->attrib.map_state != IsViewable || \ + (!(w)->damaged) || \ + (w)->attrib.x + (w)->width + (w)->output.right <= 0 || \ + (w)->attrib.y + (w)->height + (w)->output.bottom <= 0 || \ + (w)->attrib.x - (w)->output.left >= (w)->screen->width () || \ + (w)->attrib.y - (w)->output.top >= (w)->screen->height () ) + + +class PrivateWindow { + + public: + PrivateWindow (CompWindow *window); + ~PrivateWindow (); + + void + recalcNormalHints (); + + void + updateFrameWindow (); + + void + setWindowMatrix (); + + bool + restack (Window aboveId); + + bool + initializeSyncCounter (); + + bool + isGroupTransient (Window clientLeader); + + + static bool + stackLayerCheck (CompWindow *w, + Window clientLeader, + CompWindow *below); + + static bool + avoidStackingRelativeTo (CompWindow *w); + + static CompWindow * + findSiblingBelow (CompWindow *w, + bool aboveFs); + + static CompWindow * + findLowestSiblingBelow (CompWindow *w); + + static bool + validSiblingBelow (CompWindow *w, + CompWindow *sibling); + + void + saveGeometry (int mask); + + int + restoreGeometry (XWindowChanges *xwc, int mask); + + void + reconfigureXWindow (unsigned int valueMask, + XWindowChanges *xwc); + + static bool + stackTransients (CompWindow *w, + CompWindow *avoid, + XWindowChanges *xwc); + + static void + stackAncestors (CompWindow *w, XWindowChanges *xwc); + + static bool + isAncestorTo (CompWindow *transient, + CompWindow *ancestor); + + Window + getClientLeaderOfAncestor (); + + CompWindow * + getModalTransient (); + + int + addWindowSizeChanges (XWindowChanges *xwc, + int oldX, + int oldY, + int oldWidth, + int oldHeight, + int oldBorderWidth); + + int + addWindowStackChanges (XWindowChanges *xwc, + CompWindow *sibling); + + static CompWindow * + findValidStackSiblingBelow (CompWindow *w, + CompWindow *sibling); + + void + ensureWindowVisibility (); + + void + reveal (); + + static void + revealAncestors (CompWindow *w, + void *closure); + + bool + constrainNewWindowSize (int width, + int height, + int *newWidth, + int *newHeight); + + static void + minimizeTransients (CompWindow *w, + void *closure); + + static void + unminimizeTransients (CompWindow *w, + void *closure); + + bool + getUsageTimestamp (Time *timestamp); + + bool + isWindowFocusAllowed (Time timestamp); + + static void + handleDamageRect (CompWindow *w, + int x, + int y, + int width, + int height); + + + public: + + CompWindow *window; + CompScreen *screen; + + int refcnt; + Window id; + Window frame; + unsigned int mapNum; + unsigned int activeNum; + XWindowAttributes attrib; + int serverX; + int serverY; + int serverWidth; + int serverHeight; + int serverBorderWidth; + Window transientFor; + Window clientLeader; + XSizeHints sizeHints; + Pixmap pixmap; + CompTexture *texture; + CompMatrix matrix; + Damage damage; + bool inputHint; + bool alpha; + GLint width; + GLint height; + Region region; + Region clip; + unsigned int wmType; + unsigned int type; + unsigned int state; + unsigned int actions; + unsigned int protocols; + unsigned int mwmDecor; + unsigned int mwmFunc; + bool invisible; + bool destroyed; + bool damaged; + bool redirected; + bool managed; + bool bindFailed; + bool overlayWindow; + int destroyRefCnt; + int unmapRefCnt; + + unsigned int initialViewportX; + unsigned int initialViewportY; + + Time initialTimestamp; + Bool initialTimestampSet; + + bool placed; + bool minimized; + bool inShowDesktopMode; + bool shaded; + bool hidden; + bool grabbed; + + unsigned int desktop; + + int pendingUnmaps; + int pendingMaps; + + char *startupId; + char *resName; + char *resClass; + + CompGroup *group; + + unsigned int lastPong; + bool alive; + + GLushort opacity; + GLushort brightness; + GLushort saturation; + + WindowPaintAttrib paint; + WindowPaintAttrib lastPaint; + + unsigned int lastMask; + + CompWindowExtents input; + CompWindowExtents output; + + CompStruts *struts; + + CompIcon **icon; + int nIcon; + + XRectangle iconGeometry; + bool iconGeometrySet; + + XWindowChanges saveWc; + int saveMask; + + XSyncCounter syncCounter; + XSyncValue syncValue; + XSyncAlarm syncAlarm; + unsigned long syncAlarmConnection; + unsigned int syncWaitHandle; + + bool syncWait; + int syncX; + int syncY; + int syncWidth; + int syncHeight; + int syncBorderWidth; + + bool closeRequests; + Time lastCloseRequestTime; + + XRectangle *damageRects; + int sizeDamage; + int nDamage; + + GLfloat *vertices; + int vertexSize; + int vertexStride; + GLushort *indices; + int indexSize; + int vCount; + int texUnits; + int texCoordSize; + int indexCount; +}; + +#endif diff --git a/src/screen.cpp b/src/screen.cpp index c1b8594..b10f915 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -47,7 +47,10 @@ #include <compiz-core.h> -#define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption)) +#include <compscreen.h> +#include "privatescreen.h" + +#define NUM_OPTIONS(s) (sizeof ((s)->priv->opt) / sizeof (CompOption)) static int reallocScreenPrivate (int size, @@ -57,13 +60,13 @@ reallocScreenPrivate (int size, CompScreen *s; void *privates; - for (s = d->screens; s; s = s->next) + for (s = d->screens(); s; s = s->next) { - privates = realloc (s->base.privates, size * sizeof (CompPrivate)); + privates = realloc (s->privates, size * sizeof (CompPrivate)); if (!privates) return FALSE; - s->base.privates = (CompPrivate *) privates; + s->privates = (CompPrivate *) privates; } return TRUE; @@ -102,9 +105,9 @@ forEachScreenObject (CompObject *parent, CORE_DISPLAY (parent); - for (s = d->screens; s; s = s->next) + for (s = d->screens(); s; s = s->next) { - if (!(*proc) (&s->base, closure)) + if (!(*proc) (s, closure)) return FALSE; } } @@ -119,7 +122,7 @@ nameScreenObject (CompObject *object) CORE_SCREEN (object); - snprintf (tmp, 256, "%d", s->screenNum); + snprintf (tmp, 256, "%d", s->screenNum ()); return strdup (tmp); } @@ -135,9 +138,9 @@ findScreenObject (CompObject *parent, CORE_DISPLAY (parent); - for (s = d->screens; s; s = s->next) - if (s->screenNum == screenNum) - return &s->base; + for (s = d->screens(); s; s = s->next) + if (s->screenNum () == screenNum) + return s; } return NULL; @@ -146,126 +149,125 @@ findScreenObject (CompObject *parent, int allocateScreenPrivateIndex (CompDisplay *display) { - return compObjectAllocatePrivateIndex (&display->base, - COMP_OBJECT_TYPE_SCREEN); + return compObjectAllocatePrivateIndex (display, COMP_OBJECT_TYPE_SCREEN); } void freeScreenPrivateIndex (CompDisplay *display, int index) { - compObjectFreePrivateIndex (&display->base, - COMP_OBJECT_TYPE_SCREEN, - index); + compObjectFreePrivateIndex (display, COMP_OBJECT_TYPE_SCREEN, index); } -static Bool -desktopHintEqual (CompScreen *s, - unsigned long *data, - int size, - int offset, - int hintSize) + +bool +PrivateScreen::desktopHintEqual (unsigned long *data, + int size, + int offset, + int hintSize) { - if (size != s->desktopHintSize) - return FALSE; + if (size != desktopHintSize) + return false; if (memcmp (data + offset, - s->desktopHintData + offset, + desktopHintData + offset, hintSize * sizeof (unsigned long)) == 0) - return TRUE; + return true; - return FALSE; + return false; } -static void -setDesktopHints (CompScreen *s) +void +PrivateScreen::setDesktopHints () { - CompDisplay *d = s->display; unsigned long *data; - int size, offset, hintSize, i; + int size, offset, hintSize; + unsigned int i; - size = s->nDesktop * 2 + s->nDesktop * 2 + s->nDesktop * 4 + 1; + size = nDesktop * 2 + nDesktop * 2 + nDesktop * 4 + 1; data = (unsigned long *) malloc (sizeof (unsigned long) * size); if (!data) return; offset = 0; - hintSize = s->nDesktop * 2; + hintSize = nDesktop * 2; - for (i = 0; i < s->nDesktop; i++) + for (i = 0; i < nDesktop; i++) { - data[offset + i * 2 + 0] = s->x * s->width; - data[offset + i * 2 + 1] = s->y * s->height; + data[offset + i * 2 + 0] = x * width; + data[offset + i * 2 + 1] = y * height; } - if (!desktopHintEqual (s, data, size, offset, hintSize)) - XChangeProperty (d->display, s->root, d->desktopViewportAtom, + if (!desktopHintEqual (data, size, offset, hintSize)) + XChangeProperty (display->dpy (), root, + display->atoms ().desktopViewport, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &data[offset], hintSize); offset += hintSize; - for (i = 0; i < s->nDesktop; i++) + for (i = 0; i < nDesktop; i++) { - data[offset + i * 2 + 0] = s->width * s->hsize; - data[offset + i * 2 + 1] = s->height * s->vsize; + data[offset + i * 2 + 0] = width * hsize; + data[offset + i * 2 + 1] = height * vsize; } - if (!desktopHintEqual (s, data, size, offset, hintSize)) - XChangeProperty (d->display, s->root, d->desktopGeometryAtom, + if (!desktopHintEqual (data, size, offset, hintSize)) + XChangeProperty (display->dpy (), root, + display->atoms ().desktopGeometry, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &data[offset], hintSize); offset += hintSize; - hintSize = s->nDesktop * 4; + hintSize = nDesktop * 4; - for (i = 0; i < s->nDesktop; i++) + for (i = 0; i < nDesktop; i++) { - data[offset + i * 4 + 0] = s->workArea.x; - data[offset + i * 4 + 1] = s->workArea.y; - data[offset + i * 4 + 2] = s->workArea.width; - data[offset + i * 4 + 3] = s->workArea.height; + data[offset + i * 4 + 0] = workArea.x; + data[offset + i * 4 + 1] = workArea.y; + data[offset + i * 4 + 2] = workArea.width; + data[offset + i * 4 + 3] = workArea.height; } - if (!desktopHintEqual (s, data, size, offset, hintSize)) - XChangeProperty (d->display, s->root, d->workareaAtom, + if (!desktopHintEqual (data, size, offset, hintSize)) + XChangeProperty (display->dpy (), root, + display->atoms ().workarea, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &data[offset], hintSize); offset += hintSize; - data[offset] = s->nDesktop; + data[offset] = nDesktop; hintSize = 1; - if (!desktopHintEqual (s, data, size, offset, hintSize)) - XChangeProperty (d->display, s->root, d->numberOfDesktopsAtom, + if (!desktopHintEqual (data, size, offset, hintSize)) + XChangeProperty (display->dpy (), root, + display->atoms ().numberOfDesktops, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &data[offset], hintSize); - if (s->desktopHintData) - free (s->desktopHintData); + if (desktopHintData) + free (desktopHintData); - s->desktopHintData = data; - s->desktopHintSize = size; + desktopHintData = data; + desktopHintSize = size; } -static void -setVirtualScreenSize (CompScreen *screen, - int hsize, - int vsize) +void +PrivateScreen::setVirtualScreenSize (int newh, int newv) { - screen->hsize = hsize; - screen->vsize = vsize; + hsize = newh; + vsize = newv; - setDesktopHints (screen); + setDesktopHints (); } -static void -updateOutputDevices (CompScreen *s) +void +PrivateScreen::updateOutputDevices () { CompOutput *o, *output = NULL; - CompListValue *list = &s->opt[COMP_SCREEN_OPTION_OUTPUTS].value.list; + CompListValue *list = &opt[COMP_SCREEN_OPTION_OUTPUTS].value.list; int nOutput = 0; int x, y, i, j, bits; unsigned int width, height; @@ -279,16 +281,16 @@ updateOutputDevices (CompScreen *s) x = 0; y = 0; - width = s->width; - height = s->height; + width = this->width; + height = this->height; bits = XParseGeometry (list->value[i].s, &x, &y, &width, &height); if (bits & XNegative) - x = s->width + x - width; + x = this->width + x - width; if (bits & YNegative) - y = s->height + y - height; + y = this->height + y - height; x1 = x; y1 = y; @@ -299,10 +301,10 @@ updateOutputDevices (CompScreen *s) x1 = 0; if (y1 < 0) y1 = 0; - if (x2 > s->width) - x2 = s->width; - if (y2 > s->height) - y2 = s->height; + if (x2 > this->width) + x2 = this->width; + if (y2 > this->height) + y2 = this->height; if (x1 < x2 && y1 < y2) { @@ -329,8 +331,8 @@ updateOutputDevices (CompScreen *s) output->region.extents.x1 = 0; output->region.extents.y1 = 0; - output->region.extents.x2 = s->width; - output->region.extents.y2 = s->height; + output->region.extents.x2 = this->width; + output->region.extents.y2 = this->height; nOutput = 1; } @@ -358,25 +360,25 @@ updateOutputDevices (CompScreen *s) output[i].id = i; } - if (s->outputDev) + if (outputDev) { - for (i = 0; i < s->nOutputDev; i++) - if (s->outputDev[i].name) - free (s->outputDev[i].name); + for (i = 0; i < nOutputDev; i++) + if (outputDev[i].name) + free (outputDev[i].name); - free (s->outputDev); + free (outputDev); } - s->outputDev = output; - s->nOutputDev = nOutput; - s->hasOverlappingOutputs = FALSE; + outputDev = output; + nOutputDev = nOutput; + hasOverlappingOutputs = false; - setCurrentOutput (s, s->currentOutputDev); + screen->setCurrentOutput (currentOutputDev); - updateWorkareaForScreen (s); + screen->updateWorkarea (); - setDefaultViewport (s); - damageScreen (s); + screen->setDefaultViewport (); + screen->damageScreen (); region = XCreateRegion (); if (region) @@ -393,18 +395,18 @@ updateOutputDevices (CompScreen *s) &output[j].region, region); if (REGION_NOT_EMPTY (region)) - s->hasOverlappingOutputs = TRUE; + hasOverlappingOutputs = true; } XSubtractRegion (&emptyRegion, &emptyRegion, region); - if (s->display->nScreenInfo) + if (display->nScreenInfo()) { - for (i = 0; i < s->display->nScreenInfo; i++) + for (i = 0; i < display->nScreenInfo(); i++) { - r.extents.x1 = s->display->screenInfo[i].x_org; - r.extents.y1 = s->display->screenInfo[i].y_org; - r.extents.x2 = r.extents.x1 + s->display->screenInfo[i].width; - r.extents.y2 = r.extents.y1 + s->display->screenInfo[i].height; + r.extents.x1 = display->screenInfo()[i].x_org; + r.extents.y1 = display->screenInfo()[i].y_org; + r.extents.x2 = r.extents.x1 + display->screenInfo()[i].width; + r.extents.y2 = r.extents.y1 + display->screenInfo()[i].height; XUnionRegion (region, &r, region); } @@ -413,52 +415,53 @@ updateOutputDevices (CompScreen *s) { r.extents.x1 = 0; r.extents.y1 = 0; - r.extents.x2 = s->width; - r.extents.y2 = s->height; + r.extents.x2 = this->width; + r.extents.y2 = this->height; XUnionRegion (region, &r, region); } /* remove all output regions from visible screen region */ - for (i = 0; i < s->nOutputDev; i++) - XSubtractRegion (region, &s->outputDev[i].region, region); + for (i = 0; i < nOutputDev; i++) + XSubtractRegion (region, &outputDev[i].region, region); /* we should clear color buffers before swapping if we have visible regions without output */ - s->clearBuffers = REGION_NOT_EMPTY (region); + clearBuffers = REGION_NOT_EMPTY (region); XDestroyRegion (region); } - (*s->outputChangeNotify) (s); + screen->outputChangeNotify (); } -static void -detectOutputDevices (CompScreen *s) +void +PrivateScreen::detectOutputDevices () { - if (!noDetection && s->opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b) + if (!noDetection && opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b) { char *name; CompOptionValue value; char output[1024]; int i, size = sizeof (output); - if (s->display->nScreenInfo) + if (display->nScreenInfo()) { - int n = s->display->nScreenInfo; + int n = display->nScreenInfo(); value.list.nValue = n; - value.list.value = (CompOptionValue *) malloc (sizeof (CompOptionValue) * n); + value.list.value = (CompOptionValue *) + malloc (sizeof (CompOptionValue) * n); if (!value.list.value) return; for (i = 0; i < n; i++) { snprintf (output, size, "%dx%d+%d+%d", - s->display->screenInfo[i].width, - s->display->screenInfo[i].height, - s->display->screenInfo[i].x_org, - s->display->screenInfo[i].y_org); + display->screenInfo()[i].width, + display->screenInfo()[i].height, + display->screenInfo()[i].x_org, + display->screenInfo()[i].y_org); value.list.value[i].s = strdup (output); } @@ -470,16 +473,16 @@ detectOutputDevices (CompScreen *s) if (!value.list.value) return; - snprintf (output, size, "%dx%d+%d+%d", s->width, s->height, 0, 0); + snprintf (output, size, "%dx%d+%d+%d", width, height, 0, 0); value.list.value->s = strdup (output); } - name = s->opt[COMP_SCREEN_OPTION_OUTPUTS].name; + name = opt[COMP_SCREEN_OPTION_OUTPUTS].name; - s->opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b = FALSE; - (*core.setOptionForPlugin) (&s->base, "core", name, &value); - s->opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b = TRUE; + opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b = false; + core->setOptionForPlugin (screen, "core", name, &value); + opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b = true; for (i = 0; i < value.list.nValue; i++) if (value.list.value[i].s) @@ -489,60 +492,66 @@ detectOutputDevices (CompScreen *s) } else { - updateOutputDevices (s); + updateOutputDevices (); } } CompOption * -getScreenOptions (CompPlugin *plugin, - CompScreen *screen, - int *count) +CompScreen::getScreenOptions (CompObject *object, + int *count) { + CompScreen *screen = (CompScreen *) object; *count = NUM_OPTIONS (screen); - return screen->opt; + return screen->priv->opt; } -Bool -setScreenOption (CompPlugin *plugin, - CompScreen *screen, +bool +setScreenOption (CompObject *object, const char *name, CompOptionValue *value) { + return ((CompScreen *) object)->setOption (name, value); +} + +bool +CompScreen::setOption (const char *name, + CompOptionValue *value) +{ CompOption *o; int index; - o = compFindOption (screen->opt, NUM_OPTIONS (screen), name, &index); + o = compFindOption (priv->opt, NUM_OPTIONS (this), name, &index); if (!o) - return FALSE; + return false; switch (index) { case COMP_SCREEN_OPTION_DETECT_REFRESH_RATE: if (compSetBoolOption (o, value)) { if (value->b) - detectRefreshRateOfScreen (screen); + detectRefreshRate (); - return TRUE; + return true; } break; case COMP_SCREEN_OPTION_DETECT_OUTPUTS: if (compSetBoolOption (o, value)) { if (value->b) - detectOutputDevices (screen); + priv->detectOutputDevices (); - return TRUE; + return true; } break; case COMP_SCREEN_OPTION_REFRESH_RATE: - if (screen->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b) - return FALSE; + if (priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b) + return false; if (compSetIntOption (o, value)) { - screen->redrawTime = 1000 / o->value.i; - screen->optimalRedrawTime = screen->redrawTime; - return TRUE; + priv->redrawTime = 1000 / o->value.i; + priv->optimalRedrawTime = priv->redrawTime; + return true; } break; case COMP_SCREEN_OPTION_HSIZE: @@ -550,17 +559,17 @@ setScreenOption (CompPlugin *plugin, { CompOption *vsize; - vsize = compFindOption (screen->opt, NUM_OPTIONS (screen), + vsize = compFindOption (priv->opt, NUM_OPTIONS (this), "vsize", NULL); if (!vsize) - return FALSE; + return false; - if (o->value.i * screen->width > MAXSHORT) - return FALSE; + if (o->value.i * priv->width > MAXSHORT) + return false; - setVirtualScreenSize (screen, o->value.i, vsize->value.i); - return TRUE; + priv->setVirtualScreenSize (o->value.i, vsize->value.i); + return true; } break; case COMP_SCREEN_OPTION_VSIZE: @@ -568,81 +577,55 @@ setScreenOption (CompPlugin *plugin, { CompOption *hsize; - hsize = compFindOption (screen->opt, NUM_OPTIONS (screen), + hsize = compFindOption (priv->opt, NUM_OPTIONS (this), "hsize", NULL); if (!hsize) - return FALSE; + return false; - if (o->value.i * screen->height > MAXSHORT) - return FALSE; + if (o->value.i * priv->height > MAXSHORT) + return false; - setVirtualScreenSize (screen, hsize->value.i, o->value.i); - return TRUE; + priv->setVirtualScreenSize (hsize->value.i, o->value.i); + return true; } break; case COMP_SCREEN_OPTION_NUMBER_OF_DESKTOPS: if (compSetIntOption (o, value)) { - setNumberOfDesktops (screen, o->value.i); - return TRUE; + setNumberOfDesktops (o->value.i); + return true; } break; case COMP_SCREEN_OPTION_DEFAULT_ICON: if (compSetStringOption (o, value)) - return updateDefaultIcon (screen); + return updateDefaultIcon (); break; case COMP_SCREEN_OPTION_OUTPUTS: if (!noDetection && - screen->opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b) - return FALSE; - - if (compSetOptionList (o, value)) - { - updateOutputDevices (screen); - return TRUE; - } - break; - case COMP_SCREEN_OPTION_OPACITY_MATCHES: - if (compSetOptionList (o, value)) - { - CompWindow *w; - int i; + priv->opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b) + return false; - for (i = 0; i < o->value.list.nValue; i++) - matchUpdate (screen->display, &o->value.list.value[i].match); - - for (w = screen->windows; w; w = w->next) - updateWindowOpacity (w); - - return TRUE; - } - break; - case COMP_SCREEN_OPTION_OPACITY_VALUES: if (compSetOptionList (o, value)) { - CompWindow *w; - - for (w = screen->windows; w; w = w->next) - updateWindowOpacity (w); - - return TRUE; + priv->updateOutputDevices (); + return true; } break; case COMP_SCREEN_OPTION_FORCE_INDEPENDENT: if (compSetBoolOption (o, value)) { - updateOutputDevices (screen); - return TRUE; + priv->updateOutputDevices (); + return true; } break; default: - if (compSetScreenOption (screen, o, value)) - return TRUE; + if (compSetScreenOption (this, o, value)) + return true; break; } - return FALSE; + return false; } const CompMetadataOptionInfo coreScreenOptionInfo[COMP_SCREEN_OPTION_NUM] = { @@ -663,34 +646,40 @@ const CompMetadataOptionInfo coreScreenOptionInfo[COMP_SCREEN_OPTION_NUM] = { { "focus_prevention_level", "int", RESTOSTRING (0, FOCUS_PREVENTION_LEVEL_LAST), 0, 0 }, { "focus_prevention_match", "match", 0, 0, 0 }, - { "opacity_matches", "list", "<type>match</type>", 0, 0 }, - { "opacity_values", "list", "<type>int</type>", 0, 0 }, { "texture_compression", "bool", 0, 0, 0 }, { "force_independent_output_painting", "bool", 0, 0, 0 } }; -static void -updateStartupFeedback (CompScreen *s) +void +PrivateScreen::updateStartupFeedback () { - if (s->startupSequences) - XDefineCursor (s->display->display, s->root, s->busyCursor); + if (startupSequences) + XDefineCursor (display->dpy (), root, busyCursor); else - XDefineCursor (s->display->display, s->root, s->normalCursor); + XDefineCursor (display->dpy (), root, normalCursor); } #define STARTUP_TIMEOUT_DELAY 15000 -static Bool -startupSequenceTimeout (void *data) +bool +CompScreen::startupSequenceTimeout (void *data) +{ + CompScreen *screen = (CompScreen *) data; + + screen->priv->handleStartupSequenceTimeout (); + return true; +} + +void +PrivateScreen::handleStartupSequenceTimeout() { - CompScreen *screen = (CompScreen *) data; CompStartupSequence *s; struct timeval now, active; double elapsed; gettimeofday (&now, NULL); - for (s = screen->startupSequences; s; s = s->next) + for (s = startupSequences; s; s = s->next) { sn_startup_sequence_get_last_active_time (s->sequence, &active.tv_sec, @@ -702,13 +691,10 @@ startupSequenceTimeout (void *data) if (elapsed > STARTUP_TIMEOUT_DELAY) sn_startup_sequence_complete (s->sequence); } - - return TRUE; } -static void -addSequence (CompScreen *screen, - SnStartupSequence *sequence) +void +PrivateScreen::addSequence (SnStartupSequence *sequence) { CompStartupSequence *s; @@ -718,28 +704,27 @@ addSequence (CompScreen *screen, sn_startup_sequence_ref (sequence); - s->next = screen->startupSequences; + s->next = startupSequences; s->sequence = sequence; - s->viewportX = screen->x; - s->viewportY = screen->y; + s->viewportX = x; + s->viewportY = y; - screen->startupSequences = s; + startupSequences = s; - if (!screen->startupSequenceTimeoutHandle) - compAddTimeout (1000, 1500, - startupSequenceTimeout, - screen); + if (!startupSequenceTimeoutHandle) + core->addTimeout (1000, 1500, + CompScreen::startupSequenceTimeout, + this); - updateStartupFeedback (screen); + updateStartupFeedback (); } -static void -removeSequence (CompScreen *screen, - SnStartupSequence *sequence) +void +PrivateScreen::removeSequence (SnStartupSequence *sequence) { CompStartupSequence *s, *p = NULL; - for (s = screen->startupSequences; s; s = s->next) + for (s = startupSequences; s; s = s->next) { if (s->sequence == sequence) break; @@ -755,22 +740,22 @@ removeSequence (CompScreen *screen, if (p) p->next = s->next; else - screen->startupSequences = NULL; + startupSequences = NULL; free (s); - if (!screen->startupSequences && screen->startupSequenceTimeoutHandle) + if (!startupSequences && startupSequenceTimeoutHandle) { - compRemoveTimeout (screen->startupSequenceTimeoutHandle); - screen->startupSequenceTimeoutHandle = 0; + core->removeTimeout (startupSequenceTimeoutHandle); + startupSequenceTimeoutHandle = 0; } - updateStartupFeedback (screen); + updateStartupFeedback (); } -static void -compScreenSnEvent (SnMonitorEvent *event, - void *userData) +void +CompScreen::compScreenSnEvent (SnMonitorEvent *event, + void *userData) { CompScreen *screen = (CompScreen *) userData; SnStartupSequence *sequence; @@ -779,10 +764,10 @@ compScreenSnEvent (SnMonitorEvent *event, switch (sn_monitor_event_get_type (event)) { case SN_MONITOR_EVENT_INITIATED: - addSequence (screen, sequence); + screen->priv->addSequence (sequence); break; case SN_MONITOR_EVENT_COMPLETED: - removeSequence (screen, sn_monitor_event_get_startup_sequence (event)); + screen->priv->removeSequence (sn_monitor_event_get_startup_sequence (event)); break; case SN_MONITOR_EVENT_CHANGED: case SN_MONITOR_EVENT_CANCELED: @@ -790,8 +775,8 @@ compScreenSnEvent (SnMonitorEvent *event, } } -static void -updateScreenEdges (CompScreen *s) +void +PrivateScreen::updateScreenEdges () { struct screenEdgeGeometry { int xw, x0; @@ -812,12 +797,12 @@ updateScreenEdges (CompScreen *s) for (i = 0; i < SCREEN_EDGE_NUM; i++) { - if (s->screenEdge[i].id) - XMoveResizeWindow (s->display->display, s->screenEdge[i].id, - geometry[i].xw * s->width + geometry[i].x0, - geometry[i].yh * s->height + geometry[i].y0, - geometry[i].ww * s->width + geometry[i].w0, - geometry[i].hh * s->height + geometry[i].h0); + if (screenEdge[i].id) + XMoveResizeWindow (display->dpy (), screenEdge[i].id, + geometry[i].xw * width + geometry[i].x0, + geometry[i].yh * height + geometry[i].y0, + geometry[i].ww * width + geometry[i].w0, + geometry[i].hh * height + geometry[i].h0); } } @@ -866,36 +851,24 @@ perspective (GLfloat *m, } void -setCurrentOutput (CompScreen *s, - int outputNum) +CompScreen::setCurrentOutput (int outputNum) { - if (outputNum >= s->nOutputDev) + if (outputNum >= priv->nOutputDev) outputNum = 0; - s->currentOutputDev = outputNum; + priv->currentOutputDev = outputNum; } -static void -reshape (CompScreen *s, - int w, - int h) +void +PrivateScreen::reshape (int w, int h) { #ifdef USE_COW if (useCow) - XMoveResizeWindow (s->display->display, s->overlay, 0, 0, w, h); + XMoveResizeWindow (display->dpy (), overlay, 0, 0, w, h); #endif - if (s->display->xineramaExtension) - { - CompDisplay *d = s->display; - - if (d->screenInfo) - XFree (d->screenInfo); - - d->nScreenInfo = 0; - d->screenInfo = XineramaQueryScreens (d->display, &d->nScreenInfo); - } + display->updateScreenInfo(); glMatrixMode (GL_PROJECTION); glLoadIdentity (); @@ -905,66 +878,64 @@ reshape (CompScreen *s, glViewport (-1, -1, 2, 2); glRasterPos2f (0, 0); - s->rasterX = s->rasterY = 0; + rasterX = rasterY = 0; - perspective (s->projection, 60.0f, 1.0f, 0.1f, 100.0f); + perspective (projection, 60.0f, 1.0f, 0.1f, 100.0f); glMatrixMode (GL_PROJECTION); glLoadIdentity (); - glMultMatrixf (s->projection); + glMultMatrixf (projection); glMatrixMode (GL_MODELVIEW); - s->region.rects = &s->region.extents; - s->region.numRects = 1; - s->region.extents.x1 = 0; - s->region.extents.y1 = 0; - s->region.extents.x2 = w; - s->region.extents.y2 = h; - s->region.size = 1; - - s->width = w; - s->height = h; - - s->fullscreenOutput.name = "fullscreen"; - s->fullscreenOutput.id = ~0; - s->fullscreenOutput.width = w; - s->fullscreenOutput.height = h; - s->fullscreenOutput.region = s->region; - s->fullscreenOutput.workArea.x = 0; - s->fullscreenOutput.workArea.y = 0; - s->fullscreenOutput.workArea.width = w; - s->fullscreenOutput.workArea.height = h; + region.rects = ®ion.extents; + region.numRects = 1; + region.extents.x1 = 0; + region.extents.y1 = 0; + region.extents.x2 = w; + region.extents.y2 = h; + region.size = 1; + + width = w; + height = h; + + fullscreenOutput.name = "fullscreen"; + fullscreenOutput.id = ~0; + fullscreenOutput.width = w; + fullscreenOutput.height = h; + fullscreenOutput.region = region; + fullscreenOutput.workArea.x = 0; + fullscreenOutput.workArea.y = 0; + fullscreenOutput.workArea.width = w; + fullscreenOutput.workArea.height = h; - updateScreenEdges (s); + updateScreenEdges (); } void -configureScreen (CompScreen *s, - XConfigureEvent *ce) +CompScreen::configure (XConfigureEvent *ce) { - if (s->attrib.width != ce->width || - s->attrib.height != ce->height) + if (priv->attrib.width != ce->width || + priv->attrib.height != ce->height) { - s->attrib.width = ce->width; - s->attrib.height = ce->height; + priv->attrib.width = ce->width; + priv->attrib.height = ce->height; - reshape (s, ce->width, ce->height); + priv->reshape (ce->width, ce->height); - detectOutputDevices (s); + priv->detectOutputDevices (); - damageScreen (s); + damageScreen (); } } -static FuncPtr -getProcAddress (CompScreen *s, - const char *name) +FuncPtr +CompScreen::getProcAddress (const char *name) { static void *dlhand = NULL; FuncPtr funcPtr = NULL; - if (s->getProcAddress) - funcPtr = s->getProcAddress ((GLubyte *) name); + if (priv->getProcAddress) + funcPtr = priv->getProcAddress ((GLubyte *) name); if (!funcPtr) { @@ -984,10 +955,9 @@ getProcAddress (CompScreen *s, } void -updateScreenBackground (CompScreen *screen, - CompTexture *texture) +PrivateScreen::updateScreenBackground (CompTexture *texture) { - Display *dpy = screen->display->display; + Display *dpy = display->dpy (); Atom pixmapAtom, actualType; int actualFormat, i, status; unsigned int width = 1, height = 1, depth = 0; @@ -1000,8 +970,8 @@ updateScreenBackground (CompScreen *screen, for (i = 0; pixmap == 0 && i < 2; i++) { - status = XGetWindowProperty (dpy, screen->root, - screen->display->xBackgroundAtom[i], + status = XGetWindowProperty (dpy, root, + display->atoms ().xBackground[i], 0, 4, FALSE, AnyPropertyType, &actualType, &actualFormat, &nItems, &bytesAfter, &prop); @@ -1025,7 +995,7 @@ updateScreenBackground (CompScreen *screen, if (XGetGeometry (dpy, p, &w, &i, &i, &width, &height, &ui, &depth)) { - if (depth == screen->attrib.depth) + if (depth == attrib.depth) pixmap = p; } } @@ -1043,8 +1013,7 @@ updateScreenBackground (CompScreen *screen, finiTexture (screen, texture); initTexture (screen, texture); - if (!bindPixmapToTexture (screen, texture, pixmap, - width, height, depth)) + if (!screen->bindPixmapToTexture (texture, pixmap, width, height, depth)) { compLogMessage (NULL, "core", CompLogLevelWarn, "Couldn't bind background pixmap 0x%x to " @@ -1070,20 +1039,21 @@ updateScreenBackground (CompScreen *screen, } void -detectRefreshRateOfScreen (CompScreen *s) +CompScreen::detectRefreshRate () { - if (!noDetection && s->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b) + if (!noDetection && + priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b) { char *name; CompOptionValue value; value.i = 0; - if (s->display->randrExtension) + if (priv->display->XRandr()) { XRRScreenConfiguration *config; - config = XRRGetScreenInfo (s->display->display, s->root); + config = XRRGetScreenInfo (priv->display->dpy (), priv->root); value.i = (int) XRRConfigCurrentRate (config); XRRFreeScreenConfigInfo (config); @@ -1092,159 +1062,158 @@ detectRefreshRateOfScreen (CompScreen *s) if (value.i == 0) value.i = defaultRefreshRate; - name = s->opt[COMP_SCREEN_OPTION_REFRESH_RATE].name; + name = priv->opt[COMP_SCREEN_OPTION_REFRESH_RATE].name; - s->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b = FALSE; - (*core.setOptionForPlugin) (&s->base, "core", name, &value); - s->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b = TRUE; + priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b = false; + core->setOptionForPlugin (this, "core", name, &value); + priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b = true; } else { - s->redrawTime = 1000 / s->opt[COMP_SCREEN_OPTION_REFRESH_RATE].value.i; - s->optimalRedrawTime = s->redrawTime; + priv->redrawTime = 1000 / + priv->opt[COMP_SCREEN_OPTION_REFRESH_RATE].value.i; + priv->optimalRedrawTime = priv->redrawTime; } } -static void -setSupportingWmCheck (CompScreen *s) +void +PrivateScreen::setSupportingWmCheck () { - CompDisplay *d = s->display; - - XChangeProperty (d->display, s->grabWindow, d->supportingWmCheckAtom, + XChangeProperty (display->dpy (), grabWindow, + display->atoms ().supportingWmCheck, XA_WINDOW, 32, PropModeReplace, - (unsigned char *) &s->grabWindow, 1); + (unsigned char *) &grabWindow, 1); - XChangeProperty (d->display, s->grabWindow, d->wmNameAtom, - d->utf8StringAtom, 8, PropModeReplace, + XChangeProperty (display->dpy (), grabWindow, display->atoms ().wmName, + display->atoms ().utf8String, 8, PropModeReplace, (unsigned char *) PACKAGE, strlen (PACKAGE)); - XChangeProperty (d->display, s->grabWindow, d->winStateAtom, + XChangeProperty (display->dpy (), grabWindow, display->atoms ().winState, XA_ATOM, 32, PropModeReplace, - (unsigned char *) &d->winStateSkipTaskbarAtom, 1); - XChangeProperty (d->display, s->grabWindow, d->winStateAtom, + (unsigned char *) &display->atoms ().winStateSkipTaskbar, + 1); + XChangeProperty (display->dpy (), grabWindow, display->atoms ().winState, XA_ATOM, 32, PropModeAppend, - (unsigned char *) &d->winStateSkipPagerAtom, 1); - XChangeProperty (d->display, s->grabWindow, d->winStateAtom, + (unsigned char *) &display->atoms ().winStateSkipPager, 1); + XChangeProperty (display->dpy (), grabWindow, display->atoms ().winState, XA_ATOM, 32, PropModeAppend, - (unsigned char *) &d->winStateHiddenAtom, 1); + (unsigned char *) &display->atoms ().winStateHidden, 1); - XChangeProperty (d->display, s->root, d->supportingWmCheckAtom, + XChangeProperty (display->dpy (), root, display->atoms ().supportingWmCheck, XA_WINDOW, 32, PropModeReplace, - (unsigned char *) &s->grabWindow, 1); + (unsigned char *) &grabWindow, 1); } -static void -setSupported (CompScreen *s) +void +PrivateScreen::setSupported () { - CompDisplay *d = s->display; Atom data[256]; int i = 0; - data[i++] = d->supportedAtom; - data[i++] = d->supportingWmCheckAtom; + data[i++] = display->atoms ().supported; + data[i++] = display->atoms ().supportingWmCheck; - data[i++] = d->utf8StringAtom; + data[i++] = display->atoms ().utf8String; - data[i++] = d->clientListAtom; - data[i++] = d->clientListStackingAtom; + data[i++] = display->atoms ().clientList; + data[i++] = display->atoms ().clientListStacking; - data[i++] = d->winActiveAtom; + data[i++] = display->atoms ().winActive; - data[i++] = d->desktopViewportAtom; - data[i++] = d->desktopGeometryAtom; - data[i++] = d->currentDesktopAtom; - data[i++] = d->numberOfDesktopsAtom; - data[i++] = d->showingDesktopAtom; + data[i++] = display->atoms ().desktopViewport; + data[i++] = display->atoms ().desktopGeometry; + data[i++] = display->atoms ().currentDesktop; + data[i++] = display->atoms ().numberOfDesktops; + data[i++] = display->atoms ().showingDesktop; - data[i++] = d->workareaAtom; + data[i++] = display->atoms ().workarea; - data[i++] = d->wmNameAtom; + data[i++] = display->atoms ().wmName; /* - data[i++] = d->wmVisibleNameAtom; + data[i++] = display->atoms ().wmVisibleName; */ - data[i++] = d->wmStrutAtom; - data[i++] = d->wmStrutPartialAtom; + data[i++] = display->atoms ().wmStrut; + data[i++] = display->atoms ().wmStrutPartial; /* - data[i++] = d->wmPidAtom; + data[i++] = display->atoms ().wmPid; */ - data[i++] = d->wmUserTimeAtom; - data[i++] = d->frameExtentsAtom; - data[i++] = d->frameWindowAtom; - - data[i++] = d->winStateAtom; - data[i++] = d->winStateModalAtom; - data[i++] = d->winStateStickyAtom; - data[i++] = d->winStateMaximizedVertAtom; - data[i++] = d->winStateMaximizedHorzAtom; - data[i++] = d->winStateShadedAtom; - data[i++] = d->winStateSkipTaskbarAtom; - data[i++] = d->winStateSkipPagerAtom; - data[i++] = d->winStateHiddenAtom; - data[i++] = d->winStateFullscreenAtom; - data[i++] = d->winStateAboveAtom; - data[i++] = d->winStateBelowAtom; - data[i++] = d->winStateDemandsAttentionAtom; - - data[i++] = d->winOpacityAtom; - data[i++] = d->winBrightnessAtom; - - if (s->canDoSaturated) - { - data[i++] = d->winSaturationAtom; - data[i++] = d->winStateDisplayModalAtom; - } - - data[i++] = d->wmAllowedActionsAtom; - - data[i++] = d->winActionMoveAtom; - data[i++] = d->winActionResizeAtom; - data[i++] = d->winActionStickAtom; - data[i++] = d->winActionMinimizeAtom; - data[i++] = d->winActionMaximizeHorzAtom; - data[i++] = d->winActionMaximizeVertAtom; - data[i++] = d->winActionFullscreenAtom; - data[i++] = d->winActionCloseAtom; - data[i++] = d->winActionShadeAtom; - data[i++] = d->winActionChangeDesktopAtom; - data[i++] = d->winActionAboveAtom; - data[i++] = d->winActionBelowAtom; - - data[i++] = d->winTypeAtom; - data[i++] = d->winTypeDesktopAtom; - data[i++] = d->winTypeDockAtom; - data[i++] = d->winTypeToolbarAtom; - data[i++] = d->winTypeMenuAtom; - data[i++] = d->winTypeSplashAtom; - data[i++] = d->winTypeDialogAtom; - data[i++] = d->winTypeUtilAtom; - data[i++] = d->winTypeNormalAtom; - - data[i++] = d->wmDeleteWindowAtom; - data[i++] = d->wmPingAtom; - - data[i++] = d->wmMoveResizeAtom; - data[i++] = d->moveResizeWindowAtom; - data[i++] = d->restackWindowAtom; - - XChangeProperty (d->display, s->root, d->supportedAtom, XA_ATOM, 32, - PropModeReplace, (unsigned char *) data, i); + data[i++] = display->atoms ().wmUserTime; + data[i++] = display->atoms ().frameExtents; + data[i++] = display->atoms ().frameWindow; + + data[i++] = display->atoms ().winState; + data[i++] = display->atoms ().winStateModal; + data[i++] = display->atoms ().winStateSticky; + data[i++] = display->atoms ().winStateMaximizedVert; + data[i++] = display->atoms ().winStateMaximizedHorz; + data[i++] = display->atoms ().winStateShaded; + data[i++] = display->atoms ().winStateSkipTaskbar; + data[i++] = display->atoms ().winStateSkipPager; + data[i++] = display->atoms ().winStateHidden; + data[i++] = display->atoms ().winStateFullscreen; + data[i++] = display->atoms ().winStateAbove; + data[i++] = display->atoms ().winStateBelow; + data[i++] = display->atoms ().winStateDemandsAttention; + + data[i++] = display->atoms ().winOpacity; + data[i++] = display->atoms ().winBrightness; + + if (canDoSaturated) + { + data[i++] = display->atoms ().winSaturation; + data[i++] = display->atoms ().winStateDisplayModal; + } + + data[i++] = display->atoms ().wmAllowedActions; + + data[i++] = display->atoms ().winActionMove; + data[i++] = display->atoms ().winActionResize; + data[i++] = display->atoms ().winActionStick; + data[i++] = display->atoms ().winActionMinimize; + data[i++] = display->atoms ().winActionMaximizeHorz; + data[i++] = display->atoms ().winActionMaximizeVert; + data[i++] = display->atoms ().winActionFullscreen; + data[i++] = display->atoms ().winActionClose; + data[i++] = display->atoms ().winActionShade; + data[i++] = display->atoms ().winActionChangeDesktop; + data[i++] = display->atoms ().winActionAbove; + data[i++] = display->atoms ().winActionBelow; + + data[i++] = display->atoms ().winType; + data[i++] = display->atoms ().winTypeDesktop; + data[i++] = display->atoms ().winTypeDock; + data[i++] = display->atoms ().winTypeToolbar; + data[i++] = display->atoms ().winTypeMenu; + data[i++] = display->atoms ().winTypeSplash; + data[i++] = display->atoms ().winTypeDialog; + data[i++] = display->atoms ().winTypeUtil; + data[i++] = display->atoms ().winTypeNormal; + + data[i++] = display->atoms ().wmDeleteWindow; + data[i++] = display->atoms ().wmPing; + + data[i++] = display->atoms ().wmMoveResize; + data[i++] = display->atoms ().moveResizeWindow; + data[i++] = display->atoms ().restackWindow; + + XChangeProperty (display->dpy (), root, display->atoms ().supported, + XA_ATOM, 32, PropModeReplace, (unsigned char *) data, i); } -static void -getDesktopHints (CompScreen *s) +void +PrivateScreen::getDesktopHints () { - CompDisplay *d = s->display; unsigned long data[2]; Atom actual; int result, format; unsigned long n, left; unsigned char *propData; - result = XGetWindowProperty (s->display->display, s->root, - d->numberOfDesktopsAtom, 0L, 1L, FALSE, - XA_CARDINAL, &actual, &format, + result = XGetWindowProperty (display->dpy (), root, + display->atoms ().numberOfDesktops, + 0L, 1L, FALSE, XA_CARDINAL, &actual, &format, &n, &left, &propData); if (result == Success && n && propData && useDesktopHints) @@ -1253,11 +1222,11 @@ getDesktopHints (CompScreen *s) XFree (propData); if (data[0] > 0 && data[0] < 0xffffffff) - s->nDesktop = data[0]; + nDesktop = data[0]; } - result = XGetWindowProperty (s->display->display, s->root, - d->desktopViewportAtom, 0L, 2L, + result = XGetWindowProperty (display->dpy (), root, + display->atoms ().desktopViewport, 0L, 2L, FALSE, XA_CARDINAL, &actual, &format, &n, &left, &propData); @@ -1267,19 +1236,19 @@ getDesktopHints (CompScreen *s) { memcpy (data, propData, sizeof (unsigned long) * 2); - if (data[0] / s->width < s->hsize - 1) - s->x = data[0] / s->width; + if (data[0] / width < hsize - 1) + x = data[0] / width; - if (data[1] / s->height < s->vsize - 1) - s->y = data[1] / s->height; + if (data[1] / height < vsize - 1) + y = data[1] / height; } XFree (propData); } - result = XGetWindowProperty (s->display->display, s->root, - d->currentDesktopAtom, 0L, 1L, FALSE, - XA_CARDINAL, &actual, &format, + result = XGetWindowProperty (display->dpy (), root, + display->atoms ().currentDesktop, + 0L, 1L, FALSE, XA_CARDINAL, &actual, &format, &n, &left, &propData); if (result == Success && n && propData && useDesktopHints) @@ -1287,13 +1256,13 @@ getDesktopHints (CompScreen *s) memcpy (data, propData, sizeof (unsigned long)); XFree (propData); - if (data[0] < s->nDesktop) - s->currentDesktop = data[0]; + if (data[0] < nDesktop) + currentDesktop = data[0]; } - result = XGetWindowProperty (s->display->display, s->root, - d->showingDesktopAtom, 0L, 1L, FALSE, - XA_CARDINAL, &actual, &format, + result = XGetWindowProperty (display->dpy (), root, + display->atoms ().showingDesktop, + 0L, 1L, FALSE, XA_CARDINAL, &actual, &format, &n, &left, &propData); if (result == Success && n && propData) @@ -1302,65 +1271,65 @@ getDesktopHints (CompScreen *s) XFree (propData); if (data[0]) - (*s->enterShowDesktopMode) (s); + screen->enterShowDesktopMode (); } - data[0] = s->currentDesktop; + data[0] = currentDesktop; - XChangeProperty (d->display, s->root, d->currentDesktopAtom, + XChangeProperty (display->dpy (), root, display->atoms ().currentDesktop, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) data, 1); - data[0] = s->showingDesktopMask ? TRUE : FALSE; + data[0] = showingDesktopMask ? TRUE : FALSE; - XChangeProperty (d->display, s->root, d->showingDesktopAtom, + XChangeProperty (display->dpy (), root, display->atoms ().showingDesktop, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) data, 1); } void -showOutputWindow (CompScreen *s) +CompScreen::showOutputWindow () { #ifdef USE_COW if (useCow) { - Display *dpy = s->display->display; + Display *dpy = priv->display->dpy (); XserverRegion region; region = XFixesCreateRegion (dpy, NULL, 0); XFixesSetWindowShapeRegion (dpy, - s->output, + priv->output, ShapeBounding, 0, 0, 0); XFixesSetWindowShapeRegion (dpy, - s->output, + priv->output, ShapeInput, 0, 0, region); XFixesDestroyRegion (dpy, region); - damageScreen (s); + damageScreen (); } #endif } void -hideOutputWindow (CompScreen *s) +CompScreen::hideOutputWindow () { #ifdef USE_COW if (useCow) { - Display *dpy = s->display->display; + Display *dpy = priv->display->dpy (); XserverRegion region; region = XFixesCreateRegion (dpy, NULL, 0); XFixesSetWindowShapeRegion (dpy, - s->output, + priv->output, ShapeBounding, 0, 0, region); @@ -1371,13 +1340,13 @@ hideOutputWindow (CompScreen *s) } void -updateOutputWindow (CompScreen *s) +CompScreen::updateOutputWindow () { #ifdef USE_COW if (useCow) { - Display *dpy = s->display->display; + Display *dpy = priv->display->dpy (); XserverRegion region; static Region tmpRegion = NULL; CompWindow *w; @@ -1389,22 +1358,22 @@ updateOutputWindow (CompScreen *s) return; } - XSubtractRegion (&s->region, &emptyRegion, tmpRegion); + XSubtractRegion (&priv->region, &emptyRegion, tmpRegion); - for (w = s->reverseWindows; w; w = w->prev) - if (w->overlayWindow) + for (w = priv->reverseWindows; w; w = w->prev) + if (w->overlayWindow ()) { - XSubtractRegion (tmpRegion, w->region, tmpRegion); + XSubtractRegion (tmpRegion, w->region (), tmpRegion); } - XShapeCombineRegion (dpy, s->output, ShapeBounding, + XShapeCombineRegion (dpy, priv->output, ShapeBounding, 0, 0, tmpRegion, ShapeSet); region = XFixesCreateRegion (dpy, NULL, 0); XFixesSetWindowShapeRegion (dpy, - s->output, + priv->output, ShapeInput, 0, 0, region); @@ -1414,109 +1383,113 @@ updateOutputWindow (CompScreen *s) } -static void -makeOutputWindow (CompScreen *s) +void +PrivateScreen::makeOutputWindow () { #ifdef USE_COW if (useCow) { - s->overlay = XCompositeGetOverlayWindow (s->display->display, s->root); - s->output = s->overlay; + overlay = XCompositeGetOverlayWindow (display->dpy (), root); + output = overlay; - XSelectInput (s->display->display, s->output, ExposureMask); + XSelectInput (display->dpy (), output, ExposureMask); } else #endif - s->output = s->overlay = s->root; + output = overlay = root; - showOutputWindow (s); + screen->showOutputWindow (); } -static void -enterShowDesktopMode (CompScreen *s) +void +CompScreen::enterShowDesktopMode () { - CompDisplay *d = s->display; + WRAPABLE_HND_FUNC(enterShowDesktopMode) + + CompDisplay *d = priv->display; CompWindow *w; unsigned long data = 1; int count = 0; - CompOption *st = &d->opt[COMP_DISPLAY_OPTION_HIDE_SKIP_TASKBAR_WINDOWS]; + CompOption *st = d->getOption ("hide_skip_taskbar_windows"); - s->showingDesktopMask = ~(CompWindowTypeDesktopMask | - CompWindowTypeDockMask); + priv->showingDesktopMask = ~(CompWindowTypeDesktopMask | + CompWindowTypeDockMask); - for (w = s->windows; w; w = w->next) + for (w = priv->windows; w; w = w->next) { - if ((s->showingDesktopMask & w->wmType) && - (!(w->state & CompWindowStateSkipTaskbarMask) || st->value.b)) + if ((priv->showingDesktopMask & w->wmType ()) && + (!(w->state () & CompWindowStateSkipTaskbarMask) || + (st && st->value.b))) { - if (!w->inShowDesktopMode && !w->grabbed && - w->managed && (*s->focusWindow) (w)) + if (!w->inShowDesktopMode () && !w->grabbed () && + w->managed () && w->focus ()) { - w->inShowDesktopMode = TRUE; - hideWindow (w); + w->setShowDesktopMode (true); + w->hide (); } } - if (w->inShowDesktopMode) + if (w->inShowDesktopMode ()) count++; } if (!count) { - s->showingDesktopMask = 0; + priv->showingDesktopMask = 0; data = 0; } - XChangeProperty (s->display->display, s->root, - s->display->showingDesktopAtom, + XChangeProperty (priv->display->dpy (), priv->root, + priv->display->atoms ().showingDesktop, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &data, 1); } -static void -leaveShowDesktopMode (CompScreen *s, - CompWindow *window) +void +CompScreen::leaveShowDesktopMode (CompWindow *window) { + WRAPABLE_HND_FUNC(leaveShowDesktopMode, window) + CompWindow *w; unsigned long data = 0; if (window) { - if (!window->inShowDesktopMode) + if (!window->inShowDesktopMode ()) return; - window->inShowDesktopMode = FALSE; - showWindow (window); + window->setShowDesktopMode (false); + window->show (); /* return if some other window is still in show desktop mode */ - for (w = s->windows; w; w = w->next) - if (w->inShowDesktopMode) + for (w = priv->windows; w; w = w->next) + if (w->inShowDesktopMode ()) return; - s->showingDesktopMask = 0; + priv->showingDesktopMask = 0; } else { - s->showingDesktopMask = 0; + priv->showingDesktopMask = 0; - for (w = s->windows; w; w = w->next) + for (w = priv->windows; w; w = w->next) { - if (!w->inShowDesktopMode) + if (!w->inShowDesktopMode ()) continue; - w->inShowDesktopMode = FALSE; - showWindow (w); + w->setShowDesktopMode (false); + w->show (); } /* focus default window - most likely this will be the window which had focus before entering showdesktop mode */ - focusDefaultWindow (s); + focusDefaultWindow (); } - XChangeProperty (s->display->display, s->root, - s->display->showingDesktopAtom, + XChangeProperty (priv->display->dpy (), priv->root, + priv->display->atoms ().showingDesktop, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &data, 1); } @@ -1524,13 +1497,13 @@ leaveShowDesktopMode (CompScreen *s, static CompWindow * walkFirst (CompScreen *s) { - return s->windows; + return s->windows (); } static CompWindow * walkLast (CompScreen *s) { - return s->reverseWindows; + return s->reverseWindows (); } static CompWindow * @@ -1545,10 +1518,11 @@ walkPrev (CompWindow *w) return w->prev; } -static void -initWindowWalker (CompScreen *screen, - CompWalker *walker) +void +CompScreen::initWindowWalker (CompWalker *walker) { + WRAPABLE_HND_FUNC(initWindowWalker, walker) + walker->fini = NULL; walker->first = walkFirst; walker->last = walkLast; @@ -1556,69 +1530,309 @@ initWindowWalker (CompScreen *screen, walker->prev = walkPrev; } -static void -freeScreen (CompScreen *s) +CompScreen::CompScreen () { - int i, j; + WRAPABLE_INIT_HND(preparePaint); + WRAPABLE_INIT_HND(donePaint); + WRAPABLE_INIT_HND(paint); + WRAPABLE_INIT_HND(paintOutput); + WRAPABLE_INIT_HND(paintTransformedOutput); + WRAPABLE_INIT_HND(enableOutputClipping); + WRAPABLE_INIT_HND(disableOutputClipping); + WRAPABLE_INIT_HND(applyTransform); + + WRAPABLE_INIT_HND(enterShowDesktopMode); + WRAPABLE_INIT_HND(leaveShowDesktopMode); + + WRAPABLE_INIT_HND(outputChangeNotify); + + WRAPABLE_INIT_HND(initWindowWalker); + + WRAPABLE_INIT_HND(paintCursor); + WRAPABLE_INIT_HND(damageCursorRect); + + priv = new PrivateScreen (this); + assert (priv); + next = NULL; + + windowPrivateIndices = 0; + windowPrivateLen = 0; +} - if (s->outputDev) +PrivateScreen::PrivateScreen (CompScreen *screen) : + screen(screen), + display (0), + windows (0), + reverseWindows (0), + width (0), + height (0), + x (0), + y (0), + nDesktop (1), + currentDesktop (0), + damageMask (COMP_SCREEN_DAMAGE_ALL_MASK), + root (None), + overlay (None), + output (None), + grabWindow (None), + textureRectangle (false), + textureNonPowerOfTwo (false), + textureEnvCombine (false), + textureEnvCrossbar (false), + textureBorderClamp (false), + textureCompression (false), + maxTextureSize (0), + fbo (false), + fragmentProgram (false), + maxTextureUnits (1), + exposeRects (0), + sizeExpose (0), + nExpose (0), + backgroundLoaded (false), + pendingDestroys (0), + desktopWindowCount (0), + mapNum (1), + activeNum (1), + outputDev (0), + nOutputDev (0), + currentOutputDev (0), + hasOverlappingOutputs (false), + windowOffsetX (0), + windowOffsetY (0), + currentHistory (0), + overlayWindowCount (0), + snContext (0), + startupSequences (0), + startupSequenceTimeoutHandle (0), + groups (0), + defaultIcon (0), + canDoSaturated (false), + canDoSlightlySaturated (false), + clientList (0), + nClientList (0), + buttonGrab (0), + nButtonGrab (0), + keyGrab (0), + nKeyGrab (0), + grabs (0), + grabSize (0), + maxGrab (0), + rasterX (0), + rasterY (0), + nextRedraw (0), + redrawTime (1000 / defaultRefreshRate), + optimalRedrawTime (1000 / defaultRefreshRate), + frameStatus (0), + timeMult (1), + idle (true), + timeLeft (0), + pendingCommands (true), + lastFunctionId (0), + fragmentFunctions (0), + fragmentPrograms (0), + clearBuffers (true), + lighting (false), + slowAnimations (false), + showingDesktopMask (0), + desktopHintData (0), + desktopHintSize (0), + cursors (0), + cursorImages (0), + paintHandle (0), + getProcAddress (0) +{ + memset (saturateFunction, 0, sizeof (saturateFunction)); + memset (history, 0, sizeof (history)); + gettimeofday (&lastRedraw, 0); +} + +PrivateScreen::~PrivateScreen () +{ +} + +bool +CompScreen::init (CompDisplay *display, int screenNum) +{ + Display *dpy = display->dpy (); + Window newWmSnOwner = None, newCmSnOwner = None; + Atom wmSnAtom = 0, cmSnAtom = 0; + Time wmSnTimestamp = 0; + XEvent event; + XSetWindowAttributes attr; + Window currentWmSnOwner, currentCmSnOwner; + char buf[128]; + bool rv; + + sprintf (buf, "WM_S%d", screenNum); + wmSnAtom = XInternAtom (dpy, buf, 0); + + currentWmSnOwner = XGetSelectionOwner (dpy, wmSnAtom); + + if (currentWmSnOwner != None) { - for (i = 0; i < s->nOutputDev; i++) - if (s->outputDev[i].name) - free (s->outputDev[i].name); + if (!replaceCurrentWm) + { + compLogMessage (display, "core", CompLogLevelError, + "Screen %d on display \"%s\" already " + "has a window manager; try using the " + "--replace option to replace the current " + "window manager.", + screenNum, DisplayString (dpy)); + + return false; + } - free (s->outputDev); + XSelectInput (dpy, currentWmSnOwner, StructureNotifyMask); } - if (s->clientList) - free (s->clientList); + sprintf (buf, "_NET_WM_CM_S%d", screenNum); + cmSnAtom = XInternAtom (dpy, buf, 0); + + currentCmSnOwner = XGetSelectionOwner (dpy, cmSnAtom); - if (s->desktopHintData) - free (s->desktopHintData); + if (currentCmSnOwner != None) + { + if (!replaceCurrentWm) + { + compLogMessage (display, "core", CompLogLevelError, + "Screen %d on display \"%s\" already " + "has a compositing manager; try using the " + "--replace option to replace the current " + "compositing manager.", + screenNum, DisplayString (dpy)); + + return false; + } + } - if (s->buttonGrab) - free (s->buttonGrab); + attr.override_redirect = TRUE; + attr.event_mask = PropertyChangeMask; - if (s->keyGrab) - free (s->keyGrab); + newCmSnOwner = newWmSnOwner = + XCreateWindow (dpy, XRootWindow (dpy, screenNum), + -100, -100, 1, 1, 0, + CopyFromParent, CopyFromParent, + CopyFromParent, + CWOverrideRedirect | CWEventMask, + &attr); - if (s->snContext) - sn_monitor_context_unref (s->snContext); + XChangeProperty (dpy, + newWmSnOwner, + display->atoms ().wmName, + display->atoms ().utf8String, 8, + PropModeReplace, + (unsigned char *) PACKAGE, + strlen (PACKAGE)); - if (s->damage) - XDestroyRegion (s->damage); + XWindowEvent (dpy, newWmSnOwner, PropertyChangeMask, &event); - if (s->grabs) - free (s->grabs); + wmSnTimestamp = event.xproperty.time; - /* XXX: Maybe we should free all fragment functions here? But - the definition of CompFunction is private to fragment.c ... */ - for (i = 0; i < 2; i++) - for (j = 0; j < 64; j++) - if (s->saturateFunction[i][j]) - destroyFragmentFunction (s, s->saturateFunction[i][j]); + XSetSelectionOwner (dpy, wmSnAtom, newWmSnOwner, wmSnTimestamp); - compFiniScreenOptions (s, s->opt, COMP_SCREEN_OPTION_NUM); + if (XGetSelectionOwner (dpy, wmSnAtom) != newWmSnOwner) + { + compLogMessage (display, "core", CompLogLevelError, + "Could not acquire window manager " + "selection on screen %d display \"%s\"", + screenNum, DisplayString (dpy)); - if (s->windowPrivateIndices) - free (s->windowPrivateIndices); + XDestroyWindow (dpy, newWmSnOwner); - if (s->base.privates) - free (s->base.privates); + return false; + } - free (s); + /* Send client message indicating that we are now the WM */ + event.xclient.type = ClientMessage; + event.xclient.window = XRootWindow (dpy, screenNum); + event.xclient.message_type = display->atoms ().manager; + event.xclient.format = 32; + event.xclient.data.l[0] = wmSnTimestamp; + event.xclient.data.l[1] = wmSnAtom; + event.xclient.data.l[2] = 0; + event.xclient.data.l[3] = 0; + event.xclient.data.l[4] = 0; + + XSendEvent (dpy, XRootWindow (dpy, screenNum), FALSE, + StructureNotifyMask, &event); + + /* Wait for old window manager to go away */ + if (currentWmSnOwner != None) + { + do { + XWindowEvent (dpy, currentWmSnOwner, + StructureNotifyMask, &event); + } while (event.type != DestroyNotify); + } + + compCheckForError (dpy); + + XCompositeRedirectSubwindows (dpy, XRootWindow (dpy, screenNum), + CompositeRedirectManual); + + if (compCheckForError (dpy)) + { + compLogMessage (display, "core", CompLogLevelError, + "Another composite manager is already " + "running on screen: %d", screenNum); + + return false; + } + + XSetSelectionOwner (dpy, cmSnAtom, newCmSnOwner, wmSnTimestamp); + + if (XGetSelectionOwner (dpy, cmSnAtom) != newCmSnOwner) + { + compLogMessage (display, "core", CompLogLevelError, + "Could not acquire compositing manager " + "selection on screen %d display \"%s\"", + screenNum, DisplayString (dpy)); + + return false; + } + + XGrabServer (dpy); + + XSelectInput (dpy, XRootWindow (dpy, screenNum), + SubstructureRedirectMask | + SubstructureNotifyMask | + StructureNotifyMask | + PropertyChangeMask | + LeaveWindowMask | + EnterWindowMask | + KeyPressMask | + KeyReleaseMask | + ButtonPressMask | + ButtonReleaseMask | + FocusChangeMask | + ExposureMask); + + if (compCheckForError (dpy)) + { + compLogMessage (display, "core", CompLogLevelError, + "Another window manager is " + "already running on screen: %d", screenNum); + + XUngrabServer (dpy); + return false; + } + + rv = init (display, screenNum, newWmSnOwner, wmSnAtom, wmSnTimestamp); + + XUngrabServer (dpy); + return rv; } -Bool -addScreen (CompDisplay *display, - int screenNum, - Window wmSnSelectionWindow, - Atom wmSnAtom, - Time wmSnTimestamp) + +bool +CompScreen::init (CompDisplay *display, + int screenNum, + Window wmSnSelectionWindow, + Atom wmSnAtom, + Time wmSnTimestamp) { - CompScreen *s; CompPrivate *privates; - Display *dpy = display->display; + Display *dpy = display->dpy (); static char data = 0; XColor black; Pixmap bitmap; @@ -1637,235 +1851,109 @@ addScreen (CompDisplay *display, GLfloat light0Position[] = { -0.5f, 0.5f, -9.0f, 1.0f }; CompWindow *w; - s = (CompScreen *) malloc (sizeof (CompScreen)); - if (!s) - return FALSE; - - s->windowPrivateIndices = 0; - s->windowPrivateLen = 0; - if (display->screenPrivateLen) { - privates = (CompPrivate *) malloc (display->screenPrivateLen * sizeof (CompPrivate)); + privates = (CompPrivate *) + malloc (display->screenPrivateLen * sizeof (CompPrivate)); if (!privates) { - free (s); - return FALSE; + return false; } } else privates = 0; - compObjectInit (&s->base, privates, COMP_OBJECT_TYPE_SCREEN); + compObjectInit (this, privates, COMP_OBJECT_TYPE_SCREEN); - s->display = display; + priv->display = display; - if (!compInitScreenOptionsFromMetadata (s, + if (!compInitScreenOptionsFromMetadata (this, &coreMetadata, coreScreenOptionInfo, - s->opt, + priv->opt, COMP_SCREEN_OPTION_NUM)) - return FALSE; - - s->snContext = NULL; + return false; - s->damage = XCreateRegion (); - if (!s->damage) - return FALSE; + priv->damage = XCreateRegion (); + if (!priv->damage) + return false; - s->x = 0; - s->y = 0; - s->hsize = s->opt[COMP_SCREEN_OPTION_HSIZE].value.i; - s->vsize = s->opt[COMP_SCREEN_OPTION_VSIZE].value.i; - - s->windowOffsetX = 0; - s->windowOffsetY = 0; - - s->nDesktop = 1; - s->currentDesktop = 0; + priv->hsize = priv->opt[COMP_SCREEN_OPTION_HSIZE].value.i; + priv->vsize = priv->opt[COMP_SCREEN_OPTION_VSIZE].value.i; for (i = 0; i < SCREEN_EDGE_NUM; i++) { - s->screenEdge[i].id = None; - s->screenEdge[i].count = 0; + priv->screenEdge[i].id = None; + priv->screenEdge[i].count = 0; } - s->buttonGrab = 0; - s->nButtonGrab = 0; - s->keyGrab = 0; - s->nKeyGrab = 0; - - s->grabs = 0; - s->grabSize = 0; - s->maxGrab = 0; - - s->pendingDestroys = 0; - - s->clientList = 0; - s->nClientList = 0; - - s->screenNum = screenNum; - s->colormap = DefaultColormap (dpy, screenNum); - s->root = XRootWindow (dpy, screenNum); - - s->mapNum = 1; - s->activeNum = 1; - - s->groups = NULL; - - s->snContext = sn_monitor_context_new (display->snDisplay, - screenNum, - compScreenSnEvent, s, - NULL); - - s->startupSequences = NULL; - s->startupSequenceTimeoutHandle = 0; - - s->wmSnSelectionWindow = wmSnSelectionWindow; - s->wmSnAtom = wmSnAtom; - s->wmSnTimestamp = wmSnTimestamp; - - s->damageMask = COMP_SCREEN_DAMAGE_ALL_MASK; - s->next = 0; - s->exposeRects = 0; - s->sizeExpose = 0; - s->nExpose = 0; - - s->rasterX = 0; - s->rasterY = 0; - - s->outputDev = NULL; - s->nOutputDev = 0; - s->currentOutputDev = 0; - - s->windows = 0; - s->reverseWindows = 0; - - s->nextRedraw = 0; - s->frameStatus = 0; - s->timeMult = 1; - s->idle = TRUE; - s->timeLeft = 0; - - s->pendingCommands = TRUE; - - s->lastFunctionId = 0; - - s->fragmentFunctions = NULL; - s->fragmentPrograms = NULL; - - memset (s->saturateFunction, 0, sizeof (s->saturateFunction)); - - s->showingDesktopMask = 0; - - memset (s->history, 0, sizeof (s->history)); - s->currentHistory = 0; - - s->overlayWindowCount = 0; - - s->desktopHintData = NULL; - s->desktopHintSize = 0; - - s->cursors = NULL; - - s->clearBuffers = TRUE; - - gettimeofday (&s->lastRedraw, 0); - - s->preparePaintScreen = preparePaintScreen; - s->donePaintScreen = donePaintScreen; - s->paintScreen = paintScreen; - s->paintOutput = paintOutput; - s->paintTransformedOutput = paintTransformedOutput; - s->enableOutputClipping = enableOutputClipping; - s->disableOutputClipping = disableOutputClipping; - s->applyScreenTransform = applyScreenTransform; - s->paintWindow = paintWindow; - s->drawWindow = drawWindow; - s->addWindowGeometry = addWindowGeometry; - s->drawWindowTexture = drawWindowTexture; - s->damageWindowRect = damageWindowRect; - s->getOutputExtentsForWindow = getOutputExtentsForWindow; - s->getAllowedActionsForWindow = getAllowedActionsForWindow; - s->focusWindow = focusWindow; - s->activateWindow = activateWindow; - s->placeWindow = placeWindow; - s->validateWindowResizeRequest = validateWindowResizeRequest; - - s->paintCursor = paintCursor; - s->damageCursorRect = damageCursorRect; - - s->windowResizeNotify = windowResizeNotify; - s->windowMoveNotify = windowMoveNotify; - s->windowGrabNotify = windowGrabNotify; - s->windowUngrabNotify = windowUngrabNotify; + priv->screenNum = screenNum; + priv->colormap = DefaultColormap (dpy, screenNum); + priv->root = XRootWindow (dpy, screenNum); - s->enterShowDesktopMode = enterShowDesktopMode; - s->leaveShowDesktopMode = leaveShowDesktopMode; + priv->snContext = sn_monitor_context_new (display->snDisplay (), + screenNum, + compScreenSnEvent, this, + NULL); - s->windowStateChangeNotify = windowStateChangeNotify; + priv->wmSnSelectionWindow = wmSnSelectionWindow; + priv->wmSnAtom = wmSnAtom; + priv->wmSnTimestamp = wmSnTimestamp; - s->outputChangeNotify = outputChangeNotify; + if (!XGetWindowAttributes (dpy, priv->root, &priv->attrib)) + return false; - s->initWindowWalker = initWindowWalker; + priv->workArea.x = 0; + priv->workArea.y = 0; + priv->workArea.width = priv->attrib.width; + priv->workArea.height = priv->attrib.height; + priv->grabWindow = None; - s->getProcAddress = 0; + priv->makeOutputWindow (); - if (!XGetWindowAttributes (dpy, s->root, &s->attrib)) - return FALSE; - - s->workArea.x = 0; - s->workArea.y = 0; - s->workArea.width = s->attrib.width; - s->workArea.height = s->attrib.height; - - s->grabWindow = None; - - makeOutputWindow (s); - - templ.visualid = XVisualIDFromVisual (s->attrib.visual); + templ.visualid = XVisualIDFromVisual (priv->attrib.visual); visinfo = XGetVisualInfo (dpy, VisualIDMask, &templ, &nvisinfo); if (!nvisinfo) { compLogMessage (display, "core", CompLogLevelFatal, "Couldn't get visual info for default visual"); - return FALSE; + return false; } defaultDepth = visinfo->depth; black.red = black.green = black.blue = 0; - if (!XAllocColor (dpy, s->colormap, &black)) + if (!XAllocColor (dpy, priv->colormap, &black)) { compLogMessage (display, "core", CompLogLevelFatal, "Couldn't allocate color"); XFree (visinfo); - return FALSE; + return false; } - bitmap = XCreateBitmapFromData (dpy, s->root, &data, 1, 1); + bitmap = XCreateBitmapFromData (dpy, priv->root, &data, 1, 1); if (!bitmap) { compLogMessage (display, "core", CompLogLevelFatal, "Couldn't create bitmap"); XFree (visinfo); - return FALSE; + return false; } - s->invisibleCursor = XCreatePixmapCursor (dpy, bitmap, bitmap, - &black, &black, 0, 0); - if (!s->invisibleCursor) + priv->invisibleCursor = XCreatePixmapCursor (dpy, bitmap, bitmap, + &black, &black, 0, 0); + if (!priv->invisibleCursor) { compLogMessage (display, "core", CompLogLevelFatal, "Couldn't create invisible cursor"); XFree (visinfo); - return FALSE; + return false; } XFreePixmap (dpy, bitmap); - XFreeColors (dpy, s->colormap, &black.pixel, 1, 0); + XFreeColors (dpy, priv->colormap, &black.pixel, 1, 0); glXGetConfig (dpy, visinfo, GLX_USE_GL, &value); if (!value) @@ -1873,7 +1961,7 @@ addScreen (CompDisplay *display, compLogMessage (display, "core", CompLogLevelFatal, "Root visual is not a GL visual"); XFree (visinfo); - return FALSE; + return false; } glXGetConfig (dpy, visinfo, GLX_DOUBLEBUFFER, &value); @@ -1882,17 +1970,17 @@ addScreen (CompDisplay *display, compLogMessage (display, "core", CompLogLevelFatal, "Root visual is not a double buffered GL visual"); XFree (visinfo); - return FALSE; + return false; } - s->ctx = glXCreateContext (dpy, visinfo, NULL, !indirectRendering); - if (!s->ctx) + priv->ctx = glXCreateContext (dpy, visinfo, NULL, !indirectRendering); + if (!priv->ctx) { compLogMessage (display, "core", CompLogLevelFatal, "glXCreateContext failed"); XFree (visinfo); - return FALSE; + return false; } glxExtensions = glXQueryExtensionsString (dpy, screenNum); @@ -1902,7 +1990,7 @@ addScreen (CompDisplay *display, "GLX_EXT_texture_from_pixmap is missing"); XFree (visinfo); - return FALSE; + return false; } XFree (visinfo); @@ -1911,206 +1999,204 @@ addScreen (CompDisplay *display, { compLogMessage (display, "core", CompLogLevelFatal, "GLX_SGIX_fbconfig is missing"); - return FALSE; - } - - s->getProcAddress = (GLXGetProcAddressProc) - getProcAddress (s, "glXGetProcAddressARB"); - s->bindTexImage = (GLXBindTexImageProc) - getProcAddress (s, "glXBindTexImageEXT"); - s->releaseTexImage = (GLXReleaseTexImageProc) - getProcAddress (s, "glXReleaseTexImageEXT"); - s->queryDrawable = (GLXQueryDrawableProc) - getProcAddress (s, "glXQueryDrawable"); - s->getFBConfigs = (GLXGetFBConfigsProc) - getProcAddress (s, "glXGetFBConfigs"); - s->getFBConfigAttrib = (GLXGetFBConfigAttribProc) - getProcAddress (s, "glXGetFBConfigAttrib"); - s->createPixmap = (GLXCreatePixmapProc) - getProcAddress (s, "glXCreatePixmap"); - - if (!s->bindTexImage) + return false; + } + + priv->getProcAddress = (GLXGetProcAddressProc) + getProcAddress ("glXGetProcAddressARB"); + bindTexImage = (GLXBindTexImageProc) + getProcAddress ("glXBindTexImageEXT"); + releaseTexImage = (GLXReleaseTexImageProc) + getProcAddress ("glXReleaseTexImageEXT"); + queryDrawable = (GLXQueryDrawableProc) + getProcAddress ("glXQueryDrawable"); + getFBConfigs = (GLXGetFBConfigsProc) + getProcAddress ("glXGetFBConfigs"); + getFBConfigAttrib = (GLXGetFBConfigAttribProc) + getProcAddress ("glXGetFBConfigAttrib"); + createPixmap = (GLXCreatePixmapProc) + getProcAddress ("glXCreatePixmap"); + + if (!bindTexImage) { compLogMessage (display, "core", CompLogLevelFatal, "glXBindTexImageEXT is missing"); - return FALSE; + return false; } - if (!s->releaseTexImage) + if (!releaseTexImage) { compLogMessage (display, "core", CompLogLevelFatal, "glXReleaseTexImageEXT is missing"); - return FALSE; + return false; } - if (!s->queryDrawable || - !s->getFBConfigs || - !s->getFBConfigAttrib || - !s->createPixmap) + if (!queryDrawable || + !getFBConfigs || + !getFBConfigAttrib || + !createPixmap) { compLogMessage (display, "core", CompLogLevelFatal, "fbconfig functions missing"); - return FALSE; + return false; } - s->copySubBuffer = NULL; + copySubBuffer = NULL; if (strstr (glxExtensions, "GLX_MESA_copy_sub_buffer")) - s->copySubBuffer = (GLXCopySubBufferProc) - getProcAddress (s, "glXCopySubBufferMESA"); + copySubBuffer = (GLXCopySubBufferProc) + getProcAddress ("glXCopySubBufferMESA"); - s->getVideoSync = NULL; - s->waitVideoSync = NULL; + getVideoSync = NULL; + waitVideoSync = NULL; if (strstr (glxExtensions, "GLX_SGI_video_sync")) { - s->getVideoSync = (GLXGetVideoSyncProc) - getProcAddress (s, "glXGetVideoSyncSGI"); + getVideoSync = (GLXGetVideoSyncProc) + getProcAddress ("glXGetVideoSyncSGI"); - s->waitVideoSync = (GLXWaitVideoSyncProc) - getProcAddress (s, "glXWaitVideoSyncSGI"); + waitVideoSync = (GLXWaitVideoSyncProc) + getProcAddress ("glXWaitVideoSyncSGI"); } - glXMakeCurrent (dpy, s->output, s->ctx); - currentRoot = s->root; + glXMakeCurrent (dpy, priv->output, priv->ctx); + currentRoot = priv->root; glExtensions = (const char *) glGetString (GL_EXTENSIONS); if (!glExtensions) { compLogMessage (display, "core", CompLogLevelFatal, "No valid GL extensions string found."); - return FALSE; + return false; } - s->textureNonPowerOfTwo = 0; + priv->textureNonPowerOfTwo = false; if (strstr (glExtensions, "GL_ARB_texture_non_power_of_two")) - s->textureNonPowerOfTwo = 1; + priv->textureNonPowerOfTwo = true; - glGetIntegerv (GL_MAX_TEXTURE_SIZE, &s->maxTextureSize); + glGetIntegerv (GL_MAX_TEXTURE_SIZE, &priv->maxTextureSize); - s->textureRectangle = 0; + priv->textureRectangle = false; if (strstr (glExtensions, "GL_NV_texture_rectangle") || strstr (glExtensions, "GL_EXT_texture_rectangle") || strstr (glExtensions, "GL_ARB_texture_rectangle")) { - s->textureRectangle = 1; + priv->textureRectangle = true; - if (!s->textureNonPowerOfTwo) + if (!priv->textureNonPowerOfTwo) { GLint maxTextureSize; glGetIntegerv (GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, &maxTextureSize); - if (maxTextureSize > s->maxTextureSize) - s->maxTextureSize = maxTextureSize; + if (maxTextureSize > priv->maxTextureSize) + priv->maxTextureSize = maxTextureSize; } } - if (!(s->textureRectangle || s->textureNonPowerOfTwo)) + if (!(priv->textureRectangle || priv->textureNonPowerOfTwo)) { compLogMessage (display, "core", CompLogLevelFatal, "Support for non power of two textures missing"); - return FALSE; + return false; } - s->textureEnvCombine = s->textureEnvCrossbar = 0; + priv->textureEnvCombine = priv->textureEnvCrossbar = false; if (strstr (glExtensions, "GL_ARB_texture_env_combine")) { - s->textureEnvCombine = 1; + priv->textureEnvCombine = true; /* XXX: GL_NV_texture_env_combine4 need special code but it seams to be working anyway for now... */ if (strstr (glExtensions, "GL_ARB_texture_env_crossbar") || strstr (glExtensions, "GL_NV_texture_env_combine4")) - s->textureEnvCrossbar = 1; + priv->textureEnvCrossbar = true; } - s->textureBorderClamp = 0; + priv->textureBorderClamp = false; if (strstr (glExtensions, "GL_ARB_texture_border_clamp") || strstr (glExtensions, "GL_SGIS_texture_border_clamp")) - s->textureBorderClamp = 1; + priv->textureBorderClamp = true; - s->maxTextureUnits = 1; + priv->maxTextureUnits = 1; if (strstr (glExtensions, "GL_ARB_multitexture")) { - s->activeTexture = (GLActiveTextureProc) - getProcAddress (s, "glActiveTexture"); - s->clientActiveTexture = (GLClientActiveTextureProc) - getProcAddress (s, "glClientActiveTexture"); - s->multiTexCoord2f = (GLMultiTexCoord2fProc) - getProcAddress (s, "glMultiTexCoord2f"); + activeTexture = (GLActiveTextureProc) + getProcAddress ("glActiveTexture"); + clientActiveTexture = (GLClientActiveTextureProc) + getProcAddress ("glClientActiveTexture"); + multiTexCoord2f = (GLMultiTexCoord2fProc) + getProcAddress ("glMultiTexCoord2f"); - if (s->activeTexture && s->clientActiveTexture && s->multiTexCoord2f) - glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &s->maxTextureUnits); + if (activeTexture && clientActiveTexture && multiTexCoord2f) + glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &priv->maxTextureUnits); } - s->fragmentProgram = 0; + priv->fragmentProgram = false; if (strstr (glExtensions, "GL_ARB_fragment_program")) { - s->genPrograms = (GLGenProgramsProc) - getProcAddress (s, "glGenProgramsARB"); - s->deletePrograms = (GLDeleteProgramsProc) - getProcAddress (s, "glDeleteProgramsARB"); - s->bindProgram = (GLBindProgramProc) - getProcAddress (s, "glBindProgramARB"); - s->programString = (GLProgramStringProc) - getProcAddress (s, "glProgramStringARB"); - s->programEnvParameter4f = (GLProgramParameter4fProc) - getProcAddress (s, "glProgramEnvParameter4fARB"); - s->programLocalParameter4f = (GLProgramParameter4fProc) - getProcAddress (s, "glProgramLocalParameter4fARB"); - s->getProgramiv = (GLGetProgramivProc) - getProcAddress (s, "glGetProgramivARB"); - - if (s->genPrograms && - s->deletePrograms && - s->bindProgram && - s->programString && - s->programEnvParameter4f && - s->programLocalParameter4f && - s->getProgramiv) - s->fragmentProgram = 1; - } - - s->fbo = 0; + genPrograms = (GLGenProgramsProc) + getProcAddress ("glGenProgramsARB"); + deletePrograms = (GLDeleteProgramsProc) + getProcAddress ("glDeleteProgramsARB"); + bindProgram = (GLBindProgramProc) + getProcAddress ("glBindProgramARB"); + programString = (GLProgramStringProc) + getProcAddress ("glProgramStringARB"); + programEnvParameter4f = (GLProgramParameter4fProc) + getProcAddress ("glProgramEnvParameter4fARB"); + programLocalParameter4f = (GLProgramParameter4fProc) + getProcAddress ("glProgramLocalParameter4fARB"); + getProgramiv = (GLGetProgramivProc) + getProcAddress ("glGetProgramivARB"); + + if (genPrograms && + deletePrograms && + bindProgram && + programString && + programEnvParameter4f && + programLocalParameter4f && + getProgramiv) + priv->fragmentProgram = true; + } + + priv->fbo = false; if (strstr (glExtensions, "GL_EXT_framebuffer_object")) { - s->genFramebuffers = (GLGenFramebuffersProc) - getProcAddress (s, "glGenFramebuffersEXT"); - s->deleteFramebuffers = (GLDeleteFramebuffersProc) - getProcAddress (s, "glDeleteFramebuffersEXT"); - s->bindFramebuffer = (GLBindFramebufferProc) - getProcAddress (s, "glBindFramebufferEXT"); - s->checkFramebufferStatus = (GLCheckFramebufferStatusProc) - getProcAddress (s, "glCheckFramebufferStatusEXT"); - s->framebufferTexture2D = (GLFramebufferTexture2DProc) - getProcAddress (s, "glFramebufferTexture2DEXT"); - s->generateMipmap = (GLGenerateMipmapProc) - getProcAddress (s, "glGenerateMipmapEXT"); - - if (s->genFramebuffers && - s->deleteFramebuffers && - s->bindFramebuffer && - s->checkFramebufferStatus && - s->framebufferTexture2D && - s->generateMipmap) - s->fbo = 1; - } - - s->textureCompression = 0; + genFramebuffers = (GLGenFramebuffersProc) + getProcAddress ("glGenFramebuffersEXT"); + deleteFramebuffers = (GLDeleteFramebuffersProc) + getProcAddress ("glDeleteFramebuffersEXT"); + bindFramebuffer = (GLBindFramebufferProc) + getProcAddress ("glBindFramebufferEXT"); + checkFramebufferStatus = (GLCheckFramebufferStatusProc) + getProcAddress ("glCheckFramebufferStatusEXT"); + framebufferTexture2D = (GLFramebufferTexture2DProc) + getProcAddress ("glFramebufferTexture2DEXT"); + generateMipmap = (GLGenerateMipmapProc) + getProcAddress ("glGenerateMipmapEXT"); + + if (genFramebuffers && + deleteFramebuffers && + bindFramebuffer && + checkFramebufferStatus && + framebufferTexture2D && + generateMipmap) + priv->fbo = true; + } + + priv->textureCompression = false; if (strstr (glExtensions, "GL_ARB_texture_compression")) - s->textureCompression = 1; + priv->textureCompression = true; - fbConfigs = (*s->getFBConfigs) (dpy, - screenNum, - &nElements); + fbConfigs = (*getFBConfigs) (dpy, screenNum, &nElements); for (i = 0; i <= MAX_DEPTH; i++) { int j, db, stencil, depth, alpha, mipmap, rgba; - s->glxPixmapFBConfigs[i].fbConfig = NULL; - s->glxPixmapFBConfigs[i].mipmap = 0; - s->glxPixmapFBConfigs[i].yInverted = 0; - s->glxPixmapFBConfigs[i].textureFormat = 0; - s->glxPixmapFBConfigs[i].textureTargets = 0; + priv->glxPixmapFBConfigs[i].fbConfig = NULL; + priv->glxPixmapFBConfigs[i].mipmap = 0; + priv->glxPixmapFBConfigs[i].yInverted = 0; + priv->glxPixmapFBConfigs[i].textureFormat = 0; + priv->glxPixmapFBConfigs[i].textureTargets = 0; db = MAXSHORT; stencil = MAXSHORT; @@ -2134,30 +2220,30 @@ addScreen (CompDisplay *display, if (visualDepth != i) continue; - (*s->getFBConfigAttrib) (dpy, - fbConfigs[j], - GLX_ALPHA_SIZE, - &alpha); - (*s->getFBConfigAttrib) (dpy, - fbConfigs[j], - GLX_BUFFER_SIZE, - &value); + (*getFBConfigAttrib) (dpy, + fbConfigs[j], + GLX_ALPHA_SIZE, + &alpha); + (*getFBConfigAttrib) (dpy, + fbConfigs[j], + GLX_BUFFER_SIZE, + &value); if (value != i && (value - alpha) != i) continue; value = 0; if (i == 32) { - (*s->getFBConfigAttrib) (dpy, - fbConfigs[j], - GLX_BIND_TO_TEXTURE_RGBA_EXT, - &value); + (*getFBConfigAttrib) (dpy, + fbConfigs[j], + GLX_BIND_TO_TEXTURE_RGBA_EXT, + &value); if (value) { rgba = 1; - s->glxPixmapFBConfigs[i].textureFormat = + priv->glxPixmapFBConfigs[i].textureFormat = GLX_TEXTURE_FORMAT_RGBA_EXT; } } @@ -2167,92 +2253,87 @@ addScreen (CompDisplay *display, if (rgba) continue; - (*s->getFBConfigAttrib) (dpy, - fbConfigs[j], - GLX_BIND_TO_TEXTURE_RGB_EXT, - &value); + (*getFBConfigAttrib) (dpy, + fbConfigs[j], + GLX_BIND_TO_TEXTURE_RGB_EXT, + &value); if (!value) continue; - s->glxPixmapFBConfigs[i].textureFormat = + priv->glxPixmapFBConfigs[i].textureFormat = GLX_TEXTURE_FORMAT_RGB_EXT; } - (*s->getFBConfigAttrib) (dpy, - fbConfigs[j], - GLX_DOUBLEBUFFER, - &value); + (*getFBConfigAttrib) (dpy, + fbConfigs[j], + GLX_DOUBLEBUFFER, + &value); if (value > db) continue; db = value; - (*s->getFBConfigAttrib) (dpy, - fbConfigs[j], - GLX_STENCIL_SIZE, - &value); + (*getFBConfigAttrib) (dpy, + fbConfigs[j], + GLX_STENCIL_SIZE, + &value); if (value > stencil) continue; stencil = value; - (*s->getFBConfigAttrib) (dpy, - fbConfigs[j], - GLX_DEPTH_SIZE, - &value); + (*getFBConfigAttrib) (dpy, + fbConfigs[j], + GLX_DEPTH_SIZE, + &value); if (value > depth) continue; depth = value; - if (s->fbo) + if (priv->fbo) { - (*s->getFBConfigAttrib) (dpy, - fbConfigs[j], - GLX_BIND_TO_MIPMAP_TEXTURE_EXT, - &value); + (*getFBConfigAttrib) (dpy, + fbConfigs[j], + GLX_BIND_TO_MIPMAP_TEXTURE_EXT, + &value); if (value < mipmap) continue; mipmap = value; } - (*s->getFBConfigAttrib) (dpy, - fbConfigs[j], - GLX_Y_INVERTED_EXT, - &value); + (*getFBConfigAttrib) (dpy, + fbConfigs[j], + GLX_Y_INVERTED_EXT, + &value); - s->glxPixmapFBConfigs[i].yInverted = value; + priv->glxPixmapFBConfigs[i].yInverted = value; - (*s->getFBConfigAttrib) (dpy, - fbConfigs[j], - GLX_BIND_TO_TEXTURE_TARGETS_EXT, - &value); + (*getFBConfigAttrib) (dpy, + fbConfigs[j], + GLX_BIND_TO_TEXTURE_TARGETS_EXT, + &value); - s->glxPixmapFBConfigs[i].textureTargets = value; + priv->glxPixmapFBConfigs[i].textureTargets = value; - s->glxPixmapFBConfigs[i].fbConfig = fbConfigs[j]; - s->glxPixmapFBConfigs[i].mipmap = mipmap; + priv->glxPixmapFBConfigs[i].fbConfig = fbConfigs[j]; + priv->glxPixmapFBConfigs[i].mipmap = mipmap; } } if (nElements) XFree (fbConfigs); - if (!s->glxPixmapFBConfigs[defaultDepth].fbConfig) + if (!priv->glxPixmapFBConfigs[defaultDepth].fbConfig) { compLogMessage (display, "core", CompLogLevelFatal, "No GLXFBConfig for default depth, " "this isn't going to work."); - return FALSE; + return false; } - initTexture (s, &s->backgroundTexture); - s->backgroundLoaded = FALSE; - - s->defaultIcon = NULL; - - s->desktopWindowCount = 0; + initTexture (this, &priv->backgroundTexture); glClearColor (0.0, 0.0, 0.0, 1.0); glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); @@ -2263,22 +2344,19 @@ addScreen (CompDisplay *display, glEnableClientState (GL_VERTEX_ARRAY); glEnableClientState (GL_TEXTURE_COORD_ARRAY); - s->canDoSaturated = s->canDoSlightlySaturated = FALSE; - if (s->textureEnvCombine && s->maxTextureUnits >= 2) + priv->canDoSaturated = priv->canDoSlightlySaturated = false; + if (priv->textureEnvCombine && priv->maxTextureUnits >= 2) { - s->canDoSaturated = TRUE; - if (s->textureEnvCrossbar && s->maxTextureUnits >= 4) - s->canDoSlightlySaturated = TRUE; + priv->canDoSaturated = true; + if (priv->textureEnvCrossbar && priv->maxTextureUnits >= 4) + priv->canDoSlightlySaturated = true; } - s->redrawTime = 1000 / defaultRefreshRate; - s->optimalRedrawTime = s->redrawTime; + priv->reshape (priv->attrib.width, priv->attrib.height); - reshape (s, s->attrib.width, s->attrib.height); - - detectRefreshRateOfScreen (s); - detectOutputDevices (s); - updateOutputDevices (s); + detectRefreshRate (); + priv->detectOutputDevices (); + priv->updateOutputDevices (); glLightModelfv (GL_LIGHT_MODEL_AMBIENT, globalAmbient); @@ -2291,32 +2369,30 @@ addScreen (CompDisplay *display, glNormal3f (0.0f, 0.0f, -1.0f); - s->lighting = FALSE; - s->slowAnimations = FALSE; + priv->lighting = false; + priv->slowAnimations = false; - addScreenToDisplay (display, s); + priv->display->addScreenActions (this); - getDesktopHints (s); + priv->getDesktopHints (); /* TODO: bailout properly when objectInitPlugins fails */ - assert (objectInitPlugins (&s->base)); + assert (objectInitPlugins (this)); - (*core.objectAdd) (&display->base, &s->base); + core->objectAdd (display, this); - XQueryTree (dpy, s->root, + XQueryTree (dpy, priv->root, &rootReturn, &parentReturn, &children, &nchildren); for (i = 0; i < nchildren; i++) - addWindow (s, children[i], i ? children[i - 1] : 0); + new CompWindow (this, children[i], i ? children[i - 1] : 0); - for (w = s->windows; w; w = w->next) + for (w = priv->windows; w; w = w->next) { - if (w->attrib.map_state == IsViewable) + if (w->attrib ().map_state == IsViewable) { - w->activeNum = s->activeNum++; - w->damaged = TRUE; - w->invisible = WINDOW_INVISIBLE (w); + w->setActiveNum (priv->activeNum++); } } @@ -2325,26 +2401,26 @@ addScreen (CompDisplay *display, attrib.override_redirect = 1; attrib.event_mask = PropertyChangeMask; - s->grabWindow = XCreateWindow (dpy, s->root, -100, -100, 1, 1, 0, - CopyFromParent, InputOnly, CopyFromParent, - CWOverrideRedirect | CWEventMask, - &attrib); - XMapWindow (dpy, s->grabWindow); + priv->grabWindow = XCreateWindow (dpy, priv->root, -100, -100, 1, 1, 0, + CopyFromParent, InputOnly, CopyFromParent, + CWOverrideRedirect | CWEventMask, + &attrib); + XMapWindow (dpy, priv->grabWindow); for (i = 0; i < SCREEN_EDGE_NUM; i++) { long xdndVersion = 3; - s->screenEdge[i].id = XCreateWindow (dpy, s->root, -100, -100, 1, 1, 0, - CopyFromParent, InputOnly, - CopyFromParent, CWOverrideRedirect, - &attrib); + priv->screenEdge[i].id = XCreateWindow (dpy, priv->root, -100, -100, 1, 1, 0, + CopyFromParent, InputOnly, + CopyFromParent, CWOverrideRedirect, + &attrib); - XChangeProperty (dpy, s->screenEdge[i].id, display->xdndAwareAtom, + XChangeProperty (dpy, priv->screenEdge[i].id, display->atoms ().xdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char *) &xdndVersion, 1); - XSelectInput (dpy, s->screenEdge[i].id, + XSelectInput (dpy, priv->screenEdge[i].id, EnterWindowMask | LeaveWindowMask | ButtonPressMask | @@ -2352,144 +2428,178 @@ addScreen (CompDisplay *display, PointerMotionMask); } - updateScreenEdges (s); + priv->updateScreenEdges (); - setDesktopHints (s); - setSupportingWmCheck (s); - setSupported (s); + priv->setDesktopHints (); + priv->setSupportingWmCheck (); + priv->setSupported (); - s->normalCursor = XCreateFontCursor (dpy, XC_left_ptr); - s->busyCursor = XCreateFontCursor (dpy, XC_watch); + priv->normalCursor = XCreateFontCursor (dpy, XC_left_ptr); + priv->busyCursor = XCreateFontCursor (dpy, XC_watch); - XDefineCursor (dpy, s->root, s->normalCursor); + XDefineCursor (dpy, priv->root, priv->normalCursor); - s->filter[NOTHING_TRANS_FILTER] = COMP_TEXTURE_FILTER_FAST; - s->filter[SCREEN_TRANS_FILTER] = COMP_TEXTURE_FILTER_GOOD; - s->filter[WINDOW_TRANS_FILTER] = COMP_TEXTURE_FILTER_GOOD; + priv->filter[NOTHING_TRANS_FILTER] = COMP_TEXTURE_FILTER_FAST; + priv->filter[SCREEN_TRANS_FILTER] = COMP_TEXTURE_FILTER_GOOD; + priv->filter[WINDOW_TRANS_FILTER] = COMP_TEXTURE_FILTER_GOOD; - return TRUE; + priv->paintHandle = core->addTimeout (priv->optimalRedrawTime, MAXSHORT, + PrivateScreen::paintTimeout, this); + return true; } -void -removeScreen (CompScreen *s) +CompScreen::~CompScreen () { - CompDisplay *d = s->display; - CompScreen *p; - int i; + core->removeTimeout (priv->paintHandle); - for (p = d->screens; p; p = p->next) - if (p->next == s) - break; + while (priv->windows) + delete priv->windows; - if (p) - p->next = s->next; - else - d->screens = NULL; - - while (s->windows) - removeWindow (s->windows); + core->objectRemove (priv->display, this); - (*core.objectRemove) (&d->base, &s->base); + objectFiniPlugins (this); - objectFiniPlugins (&s->base); + XUngrabKey (priv->display->dpy (), AnyKey, AnyModifier, priv->root); - XUngrabKey (d->display, AnyKey, AnyModifier, s->root); - - for (i = 0; i < SCREEN_EDGE_NUM; i++) - XDestroyWindow (d->display, s->screenEdge[i].id); + for (int i = 0; i < SCREEN_EDGE_NUM; i++) + XDestroyWindow (priv->display->dpy (), priv->screenEdge[i].id); - XDestroyWindow (d->display, s->grabWindow); + XDestroyWindow (priv->display->dpy (), priv->grabWindow); - finiTexture (s, &s->backgroundTexture); + finiTexture (this, &priv->backgroundTexture); - if (s->defaultIcon) + if (priv->defaultIcon) { - finiTexture (s, &s->defaultIcon->texture); - free (s->defaultIcon); + finiTexture (this, &priv->defaultIcon->texture); + free (priv->defaultIcon); } - glXDestroyContext (d->display, s->ctx); + glXDestroyContext (priv->display->dpy (), priv->ctx); - XFreeCursor (d->display, s->invisibleCursor); + XFreeCursor (priv->display->dpy (), priv->invisibleCursor); #ifdef USE_COW if (useCow) - XCompositeReleaseOverlayWindow (s->display->display, s->root); + XCompositeReleaseOverlayWindow (priv->display->dpy (), priv->root); #endif - freeScreen (s); + int i, j; + + if (priv->outputDev) + { + for (i = 0; i < priv->nOutputDev; i++) + if (priv->outputDev[i].name) + free (priv->outputDev[i].name); + + free (priv->outputDev); + } + + if (priv->clientList) + free (priv->clientList); + + if (priv->desktopHintData) + free (priv->desktopHintData); + + if (priv->buttonGrab) + free (priv->buttonGrab); + + if (priv->keyGrab) + free (priv->keyGrab); + + if (priv->snContext) + sn_monitor_context_unref (priv->snContext); + + if (priv->damage) + XDestroyRegion (priv->damage); + + if (priv->grabs) + free (priv->grabs); + + /* XXX: Maybe we should free all fragment functions here? But + the definition of CompFunction is private to fragment.c ... */ + for (i = 0; i < 2; i++) + for (j = 0; j < 64; j++) + if (priv->saturateFunction[i][j]) + destroyFragmentFunction (this, priv->saturateFunction[i][j]); + + compFiniScreenOptions (this, priv->opt, COMP_SCREEN_OPTION_NUM); + + if (windowPrivateIndices) + free (windowPrivateIndices); + + if (privates) + free (privates); + + delete priv; } void -damageScreenRegion (CompScreen *screen, - Region region) +CompScreen::damageRegion (Region region) { - if (screen->damageMask & COMP_SCREEN_DAMAGE_ALL_MASK) + if (priv->damageMask & COMP_SCREEN_DAMAGE_ALL_MASK) return; - XUnionRegion (screen->damage, region, screen->damage); + XUnionRegion (priv->damage, region, priv->damage); - screen->damageMask |= COMP_SCREEN_DAMAGE_REGION_MASK; + priv->damageMask |= COMP_SCREEN_DAMAGE_REGION_MASK; } void -damageScreen (CompScreen *s) +CompScreen::damageScreen () { - s->damageMask |= COMP_SCREEN_DAMAGE_ALL_MASK; - s->damageMask &= ~COMP_SCREEN_DAMAGE_REGION_MASK; + priv->damageMask |= COMP_SCREEN_DAMAGE_ALL_MASK; + priv->damageMask &= ~COMP_SCREEN_DAMAGE_REGION_MASK; } void -damagePendingOnScreen (CompScreen *s) +CompScreen::damagePending () { - s->damageMask |= COMP_SCREEN_DAMAGE_PENDING_MASK; + priv->damageMask |= COMP_SCREEN_DAMAGE_PENDING_MASK; } void -forEachWindowOnScreen (CompScreen *screen, - ForEachWindowProc proc, - void *closure) +CompScreen::forEachWindow (ForEachWindowProc proc, void *closure) { CompWindow *w; - for (w = screen->windows; w; w = w->next) + for (w = priv->windows; w; w = w->next) (*proc) (w, closure); } void -focusDefaultWindow (CompScreen *s) +CompScreen::focusDefaultWindow () { - CompDisplay *d = s->display; + CompDisplay *d = priv->display; CompWindow *w; CompWindow *focus = NULL; - if (!d->opt[COMP_DISPLAY_OPTION_CLICK_TO_FOCUS].value.b) + if (!d->getOption ("click_to_focus")->value.b) { - w = findTopLevelWindowAtDisplay (d, d->below); - if (w && !(w->type & (CompWindowTypeDesktopMask | - CompWindowTypeDockMask))) + w = d->findTopLevelWindow (d->below ()); + if (w && !(w->type () & (CompWindowTypeDesktopMask | + CompWindowTypeDockMask))) { - if ((*w->screen->focusWindow) (w)) + if (w->focus ()) focus = w; } } if (!focus) { - for (w = s->reverseWindows; w; w = w->prev) + for (w = priv->reverseWindows; w; w = w->prev) { - if (w->type & CompWindowTypeDockMask) + if (w->type () & CompWindowTypeDockMask) continue; - if ((*s->focusWindow) (w)) + if (w->focus ()) { if (focus) { - if (w->type & (CompWindowTypeNormalMask | - CompWindowTypeDialogMask | - CompWindowTypeModalDialogMask)) + if (w->type () & (CompWindowTypeNormalMask | + CompWindowTypeDialogMask | + CompWindowTypeModalDialogMask)) { - if (compareWindowActiveness (focus, w) < 0) + if (CompWindow::compareWindowActiveness (focus, w) < 0) focus = w; } } @@ -2501,21 +2611,20 @@ focusDefaultWindow (CompScreen *s) if (focus) { - if (focus->id != d->activeWindow) - moveInputFocusToWindow (focus); + if (focus->id () != d->activeWindow ()) + focus->moveInputFocusTo (); } else { - XSetInputFocus (d->display, s->root, RevertToPointerRoot, + XSetInputFocus (d->dpy (), priv->root, RevertToPointerRoot, CurrentTime); } } CompWindow * -findWindowAtScreen (CompScreen *s, - Window id) +CompScreen::findWindow (Window id) { - if (lastFoundWindow && lastFoundWindow->id == id) + if (lastFoundWindow && lastFoundWindow->id () == id) { return lastFoundWindow; } @@ -2523,8 +2632,8 @@ findWindowAtScreen (CompScreen *s, { CompWindow *w; - for (w = s->windows; w; w = w->next) - if (w->id == id) + for (w = priv->windows; w; w = w->next) + if (w->id () == id) return (lastFoundWindow = w); } @@ -2532,22 +2641,21 @@ findWindowAtScreen (CompScreen *s, } CompWindow * -findTopLevelWindowAtScreen (CompScreen *s, - Window id) +CompScreen::findTopLevelWindow (Window id) { CompWindow *w; - w = findWindowAtScreen (s, id); + w = findWindow (id); if (!w) return NULL; - if (w->attrib.override_redirect) + if (w->attrib ().override_redirect) { /* likely a frame window */ - if (w->attrib.c_class == InputOnly) + if (w->attrib ().c_class == InputOnly) { - for (w = s->windows; w; w = w->next) - if (w->frame == id) + for (w = priv->windows; w; w = w->next) + if (w->frame () == id) return w; } @@ -2558,26 +2666,24 @@ findTopLevelWindowAtScreen (CompScreen *s, } void -insertWindowIntoScreen (CompScreen *s, - CompWindow *w, - Window aboveId) +CompScreen::insertWindow (CompWindow *w, Window aboveId) { CompWindow *p; - if (s->windows) + if (priv->windows) { if (!aboveId) { - w->next = s->windows; + w->next = priv->windows; w->prev = NULL; - s->windows->prev = w; - s->windows = w; + priv->windows->prev = w; + priv->windows = w; } else { - for (p = s->windows; p; p = p->next) + for (p = priv->windows; p; p = p->next) { - if (p->id == aboveId) + if (p->id () == aboveId) { if (p->next) { @@ -2591,7 +2697,7 @@ insertWindowIntoScreen (CompScreen *s, p->next = w; w->next = NULL; w->prev = p; - s->reverseWindows = w; + priv->reverseWindows = w; } break; } @@ -2606,14 +2712,13 @@ insertWindowIntoScreen (CompScreen *s, } else { - s->reverseWindows = s->windows = w; + priv->reverseWindows = priv->windows = w; w->prev = w->next = NULL; } } void -unhookWindowFromScreen (CompScreen *s, - CompWindow *w) +CompScreen::unhookWindow (CompWindow *w) { CompWindow *next, *prev; @@ -2630,7 +2735,7 @@ unhookWindowFromScreen (CompScreen *s, } else { - s->windows = next; + priv->windows = next; next->prev = NULL; } } @@ -2643,14 +2748,14 @@ unhookWindowFromScreen (CompScreen *s, } else { - s->reverseWindows = prev; + priv->reverseWindows = prev; prev->next = NULL; } } } else { - s->windows = s->reverseWindows = NULL; + priv->windows = priv->reverseWindows = NULL; } if (w == lastFoundWindow) @@ -2663,29 +2768,27 @@ unhookWindowFromScreen (CompScreen *s, ButtonPressMask | \ PointerMotionMask) int -pushScreenGrab (CompScreen *s, - Cursor cursor, - const char *name) +CompScreen::pushGrab (Cursor cursor, const char *name) { - if (s->maxGrab == 0) + if (priv->maxGrab == 0) { int status; - status = XGrabPointer (s->display->display, s->grabWindow, TRUE, + status = XGrabPointer (priv->display->dpy (), priv->grabWindow, TRUE, POINTER_GRAB_MASK, GrabModeAsync, GrabModeAsync, - s->root, cursor, + priv->root, cursor, CurrentTime); if (status == GrabSuccess) { - status = XGrabKeyboard (s->display->display, - s->grabWindow, TRUE, + status = XGrabKeyboard (priv->display->dpy (), + priv->grabWindow, TRUE, GrabModeAsync, GrabModeAsync, CurrentTime); if (status != GrabSuccess) { - XUngrabPointer (s->display->display, CurrentTime); + XUngrabPointer (priv->display->dpy (), CurrentTime); return 0; } } @@ -2694,88 +2797,84 @@ pushScreenGrab (CompScreen *s, } else { - XChangeActivePointerGrab (s->display->display, POINTER_GRAB_MASK, + XChangeActivePointerGrab (priv->display->dpy (), POINTER_GRAB_MASK, cursor, CurrentTime); } - if (s->grabSize <= s->maxGrab) + if (priv->grabSize <= priv->maxGrab) { - s->grabs = (CompGrab *) realloc (s->grabs, sizeof (CompGrab) * (s->maxGrab + 1)); - if (!s->grabs) + priv->grabs = (CompGrab *) + realloc (priv->grabs, sizeof (CompGrab) * (priv->maxGrab + 1)); + if (!priv->grabs) return 0; - s->grabSize = s->maxGrab + 1; + priv->grabSize = priv->maxGrab + 1; } - s->grabs[s->maxGrab].cursor = cursor; - s->grabs[s->maxGrab].active = TRUE; - s->grabs[s->maxGrab].name = name; + priv->grabs[priv->maxGrab].cursor = cursor; + priv->grabs[priv->maxGrab].active = TRUE; + priv->grabs[priv->maxGrab].name = name; - s->maxGrab++; + priv->maxGrab++; - return s->maxGrab; + return priv->maxGrab; } void -updateScreenGrab (CompScreen *s, - int index, - Cursor cursor) +CompScreen::updateGrab (int index, Cursor cursor) { index--; #ifdef DEBUG - if (index < 0 || index >= s->maxGrab) + if (index < 0 || index >= priv->maxGrab) abort (); #endif - XChangeActivePointerGrab (s->display->display, POINTER_GRAB_MASK, + XChangeActivePointerGrab (priv->display->dpy (), POINTER_GRAB_MASK, cursor, CurrentTime); - s->grabs[index].cursor = cursor; + priv->grabs[index].cursor = cursor; } void -removeScreenGrab (CompScreen *s, - int index, - XPoint *restorePointer) +CompScreen::removeGrab (int index, XPoint *restorePointer) { int maxGrab; index--; #ifdef DEBUG - if (index < 0 || index >= s->maxGrab) + if (index < 0 || index >= priv->maxGrab) abort (); #endif - s->grabs[index].cursor = None; - s->grabs[index].active = FALSE; + priv->grabs[index].cursor = None; + priv->grabs[index].active = FALSE; - for (maxGrab = s->maxGrab; maxGrab; maxGrab--) - if (s->grabs[maxGrab - 1].active) + for (maxGrab = priv->maxGrab; maxGrab; maxGrab--) + if (priv->grabs[maxGrab - 1].active) break; - if (maxGrab != s->maxGrab) + if (maxGrab != priv->maxGrab) { if (maxGrab) { - XChangeActivePointerGrab (s->display->display, + XChangeActivePointerGrab (priv->display->dpy (), POINTER_GRAB_MASK, - s->grabs[maxGrab - 1].cursor, + priv->grabs[maxGrab - 1].cursor, CurrentTime); } else { if (restorePointer) - warpPointer (s, - restorePointer->x - pointerX, + warpPointer (restorePointer->x - pointerX, restorePointer->y - pointerY); - XUngrabPointer (s->display->display, CurrentTime); - XUngrabKeyboard (s->display->display, CurrentTime); + XUngrabPointer (priv->display->dpy (), CurrentTime); + XUngrabKeyboard (priv->display->dpy (), CurrentTime); } - s->maxGrab = maxGrab; + priv->maxGrab = maxGrab; } } @@ -2783,82 +2882,80 @@ removeScreenGrab (CompScreen *s, It returns TRUE if a grab exists but it is NOT held by one of the plugins listed, returns FALSE otherwise. */ -Bool -otherScreenGrabExist (CompScreen *s, ...) +bool +CompScreen::otherGrabExist (const char *first, ...) { - va_list ap; - char *name; - int i; + va_list ap; + const char *name; + int i; - for (i = 0; i < s->maxGrab; i++) + for (i = 0; i < priv->maxGrab; i++) { - if (s->grabs[i].active) + if (priv->grabs[i].active) { - va_start (ap, s); + va_start (ap, first); - name = va_arg (ap, char *); + name = first; while (name) { - if (strcmp (name, s->grabs[i].name) == 0) + if (strcmp (name, priv->grabs[i].name) == 0) break; - name = va_arg (ap, char *); + name = va_arg (ap, const char *); } va_end (ap); if (!name) - return TRUE; + return true; } } - return FALSE; + return false; } -static void -grabUngrabOneKey (CompScreen *s, - unsigned int modifiers, - int keycode, - Bool grab) +void +PrivateScreen::grabUngrabOneKey (unsigned int modifiers, + int keycode, + bool grab) { if (grab) { - XGrabKey (s->display->display, + XGrabKey (display->dpy (), keycode, modifiers, - s->root, + root, TRUE, GrabModeAsync, GrabModeAsync); } else { - XUngrabKey (s->display->display, + XUngrabKey (display->dpy (), keycode, modifiers, - s->root); + root); } } -static Bool -grabUngrabKeys (CompScreen *s, - unsigned int modifiers, - int keycode, - Bool grab) +bool +PrivateScreen::grabUngrabKeys (unsigned int modifiers, + int keycode, + bool grab) { - XModifierKeymap *modMap = s->display->modMap; + XModifierKeymap *modMap = display->modMap (); int ignore, mod, k; - compCheckForError (s->display->display); + compCheckForError (display->dpy ()); - for (ignore = 0; ignore <= s->display->ignoredModMask; ignore++) + for (ignore = 0; ignore <= display->ignoredModMask (); ignore++) { - if (ignore & ~s->display->ignoredModMask) + if (ignore & ~display->ignoredModMask ()) continue; if (keycode != 0) { - grabUngrabOneKey (s, modifiers | ignore, keycode, grab); + grabUngrabOneKey (modifiers | ignore, keycode, grab); } else { @@ -2872,188 +2969,184 @@ grabUngrabKeys (CompScreen *s, { if (modMap->modifiermap[k]) { - grabUngrabOneKey ( - s, - (modifiers & ~(1 << mod)) | ignore, - modMap->modifiermap[k], - grab); + grabUngrabOneKey ((modifiers & ~(1 << mod)) | + ignore, + modMap->modifiermap[k], + grab); } } } } } - if (compCheckForError (s->display->display)) - return FALSE; + if (compCheckForError (display->dpy ())) + return false; } - return TRUE; + return true; } -static Bool -addPassiveKeyGrab (CompScreen *s, - CompKeyBinding *key) +bool +PrivateScreen::addPassiveKeyGrab (CompKeyBinding *key) { - CompKeyGrab *keyGrab; + CompKeyGrab *newKeyGrab; unsigned int mask; int i; - mask = virtualToRealModMask (s->display, key->modifiers); + mask = display->virtualToRealModMask (key->modifiers); - for (i = 0; i < s->nKeyGrab; i++) + for (i = 0; i < nKeyGrab; i++) { - if (key->keycode == s->keyGrab[i].keycode && - mask == s->keyGrab[i].modifiers) + if (key->keycode == keyGrab[i].keycode && + mask == keyGrab[i].modifiers) { - s->keyGrab[i].count++; - return TRUE; + keyGrab[i].count++; + return true; } } - keyGrab = (CompKeyGrab *) realloc (s->keyGrab, sizeof (CompKeyGrab) * (s->nKeyGrab + 1)); + newKeyGrab = (CompKeyGrab *) + realloc (keyGrab, sizeof (CompKeyGrab) * (nKeyGrab + 1)); if (!keyGrab) - return FALSE; + return false; - s->keyGrab = keyGrab; + keyGrab = newKeyGrab; if (!(mask & CompNoMask)) { - if (!grabUngrabKeys (s, mask, key->keycode, TRUE)) - return FALSE; + if (!grabUngrabKeys (mask, key->keycode, true)) + return false; } - s->keyGrab[s->nKeyGrab].keycode = key->keycode; - s->keyGrab[s->nKeyGrab].modifiers = mask; - s->keyGrab[s->nKeyGrab].count = 1; + keyGrab[nKeyGrab].keycode = key->keycode; + keyGrab[nKeyGrab].modifiers = mask; + keyGrab[nKeyGrab].count = 1; - s->nKeyGrab++; + nKeyGrab++; - return TRUE; + return true; } -static void -removePassiveKeyGrab (CompScreen *s, - CompKeyBinding *key) +void +PrivateScreen::removePassiveKeyGrab (CompKeyBinding *key) { unsigned int mask; int i; - for (i = 0; i < s->nKeyGrab; i++) + for (i = 0; i < nKeyGrab; i++) { - mask = virtualToRealModMask (s->display, key->modifiers); - if (key->keycode == s->keyGrab[i].keycode && - mask == s->keyGrab[i].modifiers) + mask = display->virtualToRealModMask (key->modifiers); + if (key->keycode == keyGrab[i].keycode && + mask == keyGrab[i].modifiers) { - s->keyGrab[i].count--; - if (s->keyGrab[i].count) + keyGrab[i].count--; + if (keyGrab[i].count) return; - memmove (s->keyGrab + i, s->keyGrab + i + 1, - (s->nKeyGrab - (i + 1)) * sizeof (CompKeyGrab)); + memmove (keyGrab + i, keyGrab + i + 1, + (nKeyGrab - (i + 1)) * sizeof (CompKeyGrab)); - s->nKeyGrab--; - s->keyGrab = (CompKeyGrab *) realloc (s->keyGrab, - sizeof (CompKeyGrab) * s->nKeyGrab); + nKeyGrab--; + keyGrab = (CompKeyGrab *) realloc (keyGrab, + sizeof (CompKeyGrab) * nKeyGrab); if (!(mask & CompNoMask)) - grabUngrabKeys (s, mask, key->keycode, FALSE); + grabUngrabKeys (mask, key->keycode, false); } } } -static void -updatePassiveKeyGrabs (CompScreen *s) +void +PrivateScreen::updatePassiveKeyGrabs () { int i; - XUngrabKey (s->display->display, AnyKey, AnyModifier, s->root); + XUngrabKey (display->dpy (), AnyKey, AnyModifier, root); - for (i = 0; i < s->nKeyGrab; i++) + for (i = 0; i < nKeyGrab; i++) { - if (!(s->keyGrab[i].modifiers & CompNoMask)) + if (!(keyGrab[i].modifiers & CompNoMask)) { - grabUngrabKeys (s, s->keyGrab[i].modifiers, - s->keyGrab[i].keycode, TRUE); + grabUngrabKeys (keyGrab[i].modifiers, + keyGrab[i].keycode, true); } } } -static Bool -addPassiveButtonGrab (CompScreen *s, - CompButtonBinding *button) +bool +PrivateScreen::addPassiveButtonGrab (CompButtonBinding *button) { - CompButtonGrab *buttonGrab; + CompButtonGrab *newButtonGrab; int i; - for (i = 0; i < s->nButtonGrab; i++) + for (i = 0; i < nButtonGrab; i++) { - if (button->button == s->buttonGrab[i].button && - button->modifiers == s->buttonGrab[i].modifiers) + if (button->button == buttonGrab[i].button && + button->modifiers == buttonGrab[i].modifiers) { - s->buttonGrab[i].count++; - return TRUE; + buttonGrab[i].count++; + return true; } } - buttonGrab = (CompButtonGrab *) realloc (s->buttonGrab, - sizeof (CompButtonGrab) * (s->nButtonGrab + 1)); + newButtonGrab = (CompButtonGrab *) + realloc (buttonGrab, sizeof (CompButtonGrab) * (nButtonGrab + 1)); + if (!buttonGrab) - return FALSE; + return false; - s->buttonGrab = buttonGrab; + buttonGrab = newButtonGrab; - s->buttonGrab[s->nButtonGrab].button = button->button; - s->buttonGrab[s->nButtonGrab].modifiers = button->modifiers; - s->buttonGrab[s->nButtonGrab].count = 1; + buttonGrab[nButtonGrab].button = button->button; + buttonGrab[nButtonGrab].modifiers = button->modifiers; + buttonGrab[nButtonGrab].count = 1; - s->nButtonGrab++; + nButtonGrab++; - return TRUE; + return true; } -static void -removePassiveButtonGrab (CompScreen *s, - CompButtonBinding *button) +void +PrivateScreen::removePassiveButtonGrab (CompButtonBinding *button) { int i; - for (i = 0; i < s->nButtonGrab; i++) + for (i = 0; i < nButtonGrab; i++) { - if (button->button == s->buttonGrab[i].button && - button->modifiers == s->buttonGrab[i].modifiers) + if (button->button == buttonGrab[i].button && + button->modifiers == buttonGrab[i].modifiers) { - s->buttonGrab[i].count--; - if (s->buttonGrab[i].count) + buttonGrab[i].count--; + if (buttonGrab[i].count) return; - memmove (s->buttonGrab + i, s->buttonGrab + i + 1, - (s->nButtonGrab - (i + 1)) * sizeof (CompButtonGrab)); + memmove (buttonGrab + i, buttonGrab + i + 1, + (nButtonGrab - (i + 1)) * sizeof (CompButtonGrab)); - s->nButtonGrab--; - s->buttonGrab = (CompButtonGrab *) realloc (s->buttonGrab, - sizeof (CompButtonGrab) * s->nButtonGrab); + nButtonGrab--; + buttonGrab = (CompButtonGrab *) + realloc (buttonGrab, sizeof (CompButtonGrab) * nButtonGrab); } } } -Bool -addScreenAction (CompScreen *s, - CompAction *action) +bool +CompScreen::addAction (CompAction *action) { if (action->type & CompBindingTypeKey) { - if (!addPassiveKeyGrab (s, &action->key)) - return FALSE; + if (!priv->addPassiveKeyGrab (&action->key)) + return true; } if (action->type & CompBindingTypeButton) { - if (!addPassiveButtonGrab (s, &action->button)) + if (!priv->addPassiveButtonGrab (&action->button)) { if (action->type & CompBindingTypeKey) - removePassiveKeyGrab (s, &action->key); + priv->removePassiveKeyGrab (&action->key); - return FALSE; + return true; } } @@ -3063,21 +3156,20 @@ addScreenAction (CompScreen *s, for (i = 0; i < SCREEN_EDGE_NUM; i++) if (action->edgeMask & (1 << i)) - enableScreenEdge (s, i); + enableEdge (i); } - return TRUE; + return true; } void -removeScreenAction (CompScreen *s, - CompAction *action) +CompScreen::removeAction (CompAction *action) { if (action->type & CompBindingTypeKey) - removePassiveKeyGrab (s, &action->key); + priv->removePassiveKeyGrab (&action->key); if (action->type & CompBindingTypeButton) - removePassiveButtonGrab (s, &action->button); + priv->removePassiveButtonGrab (&action->button); if (action->edgeMask) { @@ -3085,20 +3177,19 @@ removeScreenAction (CompScreen *s, for (i = 0; i < SCREEN_EDGE_NUM; i++) if (action->edgeMask & (1 << i)) - disableScreenEdge (s, i); + disableEdge (i); } } void -updatePassiveGrabs (CompScreen *s) +CompScreen::updatePassiveGrabs () { - updatePassiveKeyGrabs (s); + priv->updatePassiveKeyGrabs (); } -static void -computeWorkareaForBox (CompScreen *s, - BoxPtr pBox, - XRectangle *area) +void +PrivateScreen::computeWorkareaForBox (BoxPtr pBox, + XRectangle *area) { CompWindow *w; Region region; @@ -3122,20 +3213,20 @@ computeWorkareaForBox (CompScreen *s, XUnionRegion (&r, region, region); - for (w = s->windows; w; w = w->next) + for (w = windows; w; w = w->next) { - if (!w->mapNum) + if (!w->mapNum ()) continue; - if (w->struts) + if (w->struts ()) { r.extents.y1 = pBox->y1; r.extents.y2 = pBox->y2; - x1 = w->struts->left.x; - y1 = w->struts->left.y; - x2 = x1 + w->struts->left.width; - y2 = y1 + w->struts->left.height; + x1 = w->struts ()->left.x; + y1 = w->struts ()->left.y; + x2 = x1 + w->struts ()->left.width; + y2 = y1 + w->struts ()->left.height; if (y1 < pBox->y2 && y2 > pBox->y1) { @@ -3145,10 +3236,10 @@ computeWorkareaForBox (CompScreen *s, XSubtractRegion (region, &r, region); } - x1 = w->struts->right.x; - y1 = w->struts->right.y; - x2 = x1 + w->struts->right.width; - y2 = y1 + w->struts->right.height; + x1 = w->struts ()->right.x; + y1 = w->struts ()->right.y; + x2 = x1 + w->struts ()->right.width; + y2 = y1 + w->struts ()->right.height; if (y1 < pBox->y2 && y2 > pBox->y1) { @@ -3161,10 +3252,10 @@ computeWorkareaForBox (CompScreen *s, r.extents.x1 = pBox->x1; r.extents.x2 = pBox->x2; - x1 = w->struts->top.x; - y1 = w->struts->top.y; - x2 = x1 + w->struts->top.width; - y2 = y1 + w->struts->top.height; + x1 = w->struts ()->top.x; + y1 = w->struts ()->top.y; + x2 = x1 + w->struts ()->top.width; + y2 = y1 + w->struts ()->top.height; if (x1 < pBox->x2 && x2 > pBox->x1) { @@ -3174,10 +3265,10 @@ computeWorkareaForBox (CompScreen *s, XSubtractRegion (region, &r, region); } - x1 = w->struts->bottom.x; - y1 = w->struts->bottom.y; - x2 = x1 + w->struts->bottom.width; - y2 = y1 + w->struts->bottom.height; + x1 = w->struts ()->bottom.x; + y1 = w->struts ()->bottom.y; + x2 = x1 + w->struts ()->bottom.width; + y2 = y1 + w->struts ()->bottom.height; if (x1 < pBox->x2 && x2 > pBox->x1) { @@ -3198,58 +3289,57 @@ computeWorkareaForBox (CompScreen *s, } void -updateWorkareaForScreen (CompScreen *s) +CompScreen::updateWorkarea () { XRectangle workArea; BoxRec box; int i; - for (i = 0; i < s->nOutputDev; i++) - computeWorkareaForBox (s, - &s->outputDev[i].region.extents, - &s->outputDev[i].workArea); + for (i = 0; i < priv->nOutputDev; i++) + priv->computeWorkareaForBox (&priv->outputDev[i].region.extents, + &priv->outputDev[i].workArea); box.x1 = 0; box.y1 = 0; - box.x2 = s->width; - box.y2 = s->height; + box.x2 = priv->width; + box.y2 = priv->height; - computeWorkareaForBox (s, &box, &workArea); + priv->computeWorkareaForBox (&box, &workArea); - if (memcmp (&workArea, &s->workArea, sizeof (XRectangle))) + if (memcmp (&workArea, &priv->workArea, sizeof (XRectangle))) { CompWindow *w; - s->workArea = workArea; + priv->workArea = workArea; - setDesktopHints (s); + priv->setDesktopHints (); /* as work area changed, update all maximized windows on this screen to snap to the new work area */ - for (w = s->windows; w; w = w->next) - updateWindowSize (w); + for (w = priv->windows; w; w = w->next) + w->updateSize (); } } -static Bool +static bool isClientListWindow (CompWindow *w) { /* windows with client id less than 2 have been destroyed and only exists because some plugin keeps a reference to them. they should not be in client lists */ - if (w->id < 2) - return FALSE; + if (w->id () < 2) + return false; - if (w->attrib.override_redirect) - return FALSE; + if (w->attrib ().override_redirect) + return false; - if (w->attrib.map_state != IsViewable) + if (w->attrib ().map_state != IsViewable) { - if (!(w->state & CompWindowStateHiddenMask)) - return FALSE; + if (!(w->state () & CompWindowStateHiddenMask)) + return false; } - return TRUE; + return true; } static void @@ -3264,156 +3354,126 @@ countClientListWindow (CompWindow *w, } } -static void -addClientListWindow (CompWindow *w, - void *closure) -{ - if (isClientListWindow (w)) - { - int *num = (int *) closure; - - w->screen->clientList[*num] = w; - *num = *num + 1; - } -} - static int compareMappingOrder (const void *w1, const void *w2) { - return (*((CompWindow **) w1))->mapNum - (*((CompWindow **) w2))->mapNum; + return (*((CompWindow **) w1))->mapNum () - + (*((CompWindow **) w2))->mapNum (); } void -updateClientListForScreen (CompScreen *s) +CompScreen::updateClientList () { Window *clientList; Window *clientListStacking; - Bool updateClientList = FALSE; - Bool updateClientListStacking = FALSE; + Bool updateClientList = true; + Bool updateClientListStacking = true; int i, n = 0; - forEachWindowOnScreen (s, countClientListWindow, (void *) &n); + forEachWindow (countClientListWindow, (void *) &n); if (n == 0) { - if (n != s->nClientList) + if (n != priv->nClientList) { - free (s->clientList); + free (priv->clientList); - s->clientList = NULL; - s->nClientList = 0; + priv->clientList = NULL; + priv->nClientList = 0; - XChangeProperty (s->display->display, s->root, - s->display->clientListAtom, + XChangeProperty (priv->display->dpy (), priv->root, + priv->display->atoms ().clientList, XA_WINDOW, 32, PropModeReplace, - (unsigned char *) &s->grabWindow, 1); - XChangeProperty (s->display->display, s->root, - s->display->clientListStackingAtom, + (unsigned char *) &priv->grabWindow, 1); + XChangeProperty (priv->display->dpy (), priv->root, + priv->display->atoms ().clientListStacking, XA_WINDOW, 32, PropModeReplace, - (unsigned char *) &s->grabWindow, 1); + (unsigned char *) &priv->grabWindow, 1); } return; } - if (n != s->nClientList) + if (n != priv->nClientList) { CompWindow **list; - list = (CompWindow **) realloc (s->clientList, - (sizeof (CompWindow *) + sizeof (Window) * 2) * n); + list = (CompWindow **) + realloc (priv->clientList, (sizeof (CompWindow *) + + sizeof (Window) * 2) * n); if (!list) return; - s->clientList = list; - s->nClientList = n; + priv->clientList = list; + priv->nClientList = n; - updateClientList = updateClientListStacking = TRUE; + updateClientList = updateClientListStacking = true; } - clientList = (Window *) (s->clientList + n); + clientList = (Window *) (priv->clientList + n); clientListStacking = clientList + n; i = 0; - forEachWindowOnScreen (s, addClientListWindow, (void *) &i); + for (CompWindow *w = priv->windows; w; w = w->next) + if (isClientListWindow (w)) + { + priv->clientList[i] = w; + i++; + } for (i = 0; i < n; i++) { if (!updateClientListStacking) { - if (clientListStacking[i] != s->clientList[i]->id) - updateClientListStacking = TRUE; + if (clientListStacking[i] != priv->clientList[i]->id ()) + updateClientListStacking = true; } - clientListStacking[i] = s->clientList[i]->id; + clientListStacking[i] = priv->clientList[i]->id (); } /* sort window list in mapping order */ - qsort (s->clientList, n, sizeof (CompWindow *), compareMappingOrder); + qsort (priv->clientList, n, sizeof (CompWindow *), compareMappingOrder); for (i = 0; i < n; i++) { if (!updateClientList) { - if (clientList[i] != s->clientList[i]->id) - updateClientList = TRUE; + if (clientList[i] != priv->clientList[i]->id ()) + updateClientList = true; } - clientList[i] = s->clientList[i]->id; + clientList[i] = priv->clientList[i]->id (); } if (updateClientList) - XChangeProperty (s->display->display, s->root, - s->display->clientListAtom, + XChangeProperty (priv->display->dpy (), priv->root, + priv->display->atoms ().clientList, XA_WINDOW, 32, PropModeReplace, - (unsigned char *) clientList, s->nClientList); + (unsigned char *) clientList, priv->nClientList); if (updateClientListStacking) - XChangeProperty (s->display->display, s->root, - s->display->clientListStackingAtom, + XChangeProperty (priv->display->dpy (), priv->root, + priv->display->atoms ().clientListStacking, XA_WINDOW, 32, PropModeReplace, - (unsigned char *) clientListStacking, s->nClientList); -} - -Window -getActiveWindow (CompDisplay *display, - Window root) -{ - Atom actual; - int result, format; - unsigned long n, left; - unsigned char *data; - Window w = None; - - result = XGetWindowProperty (display->display, root, - display->winActiveAtom, 0L, 1L, FALSE, - XA_WINDOW, &actual, &format, - &n, &left, &data); - - if (result == Success && n && data) - { - memcpy (&w, data, sizeof (Window)); - XFree (data); - } - - return w; + (unsigned char *) clientListStacking, + priv->nClientList); } void -toolkitAction (CompScreen *s, - Atom toolkitAction, - Time eventTime, - Window window, - long data0, - long data1, - long data2) +CompScreen::toolkitAction (Atom toolkitAction, + Time eventTime, + Window window, + long data0, + long data1, + long data2) { XEvent ev; ev.type = ClientMessage; ev.xclient.window = window; - ev.xclient.message_type = s->display->toolkitActionAtom; + ev.xclient.message_type = priv->display->atoms ().toolkitAction; ev.xclient.format = 32; ev.xclient.data.l[0] = toolkitAction; ev.xclient.data.l[1] = eventTime; @@ -3421,15 +3481,15 @@ toolkitAction (CompScreen *s, ev.xclient.data.l[3] = data1; ev.xclient.data.l[4] = data2; - XUngrabPointer (s->display->display, CurrentTime); - XUngrabKeyboard (s->display->display, CurrentTime); + XUngrabPointer (priv->display->dpy (), CurrentTime); + XUngrabKeyboard (priv->display->dpy (), CurrentTime); - XSendEvent (s->display->display, s->root, FALSE, StructureNotifyMask, &ev); + XSendEvent (priv->display->dpy (), priv->root, FALSE, + StructureNotifyMask, &ev); } void -runCommand (CompScreen *s, - const char *command) +CompScreen::runCommand (const char *command) { if (*command == '\0') return; @@ -3438,13 +3498,13 @@ runCommand (CompScreen *s, { /* build a display string that uses the right screen number */ /* 5 extra chars should be enough for pretty much every situation */ - int stringLen = strlen (s->display->displayString) + 5; + int stringLen = strlen (priv->display->displayString ()) + 5; char screenString[stringLen]; char *pos, *delimiter, *colon; setsid (); - strcpy (screenString, s->display->displayString); + strcpy (screenString, priv->display->displayString ()); delimiter = strrchr (screenString, ':'); if (delimiter) { @@ -3461,7 +3521,7 @@ runCommand (CompScreen *s, pos = screenString + strlen (screenString); snprintf (pos, stringLen - (pos - screenString), - "%s.%d", colon, s->screenNum); + "%s.%d", colon, priv->screenNum); putenv (screenString); @@ -3470,150 +3530,71 @@ runCommand (CompScreen *s, } void -moveScreenViewport (CompScreen *s, - int tx, - int ty, - Bool sync) +CompScreen::moveViewport (int tx, int ty, bool sync) { CompWindow *w; int wx, wy; - tx = s->x - tx; - tx = MOD (tx, s->hsize); - tx -= s->x; + tx = priv->x - tx; + tx = MOD (tx, priv->hsize); + tx -= priv->x; - ty = s->y - ty; - ty = MOD (ty, s->vsize); - ty -= s->y; + ty = priv->y - ty; + ty = MOD (ty, priv->vsize); + ty -= priv->y; if (!tx && !ty) return; - s->x += tx; - s->y += ty; + priv->x += tx; + priv->y += ty; - tx *= -s->width; - ty *= -s->height; + tx *= -priv->width; + ty *= -priv->height; - for (w = s->windows; w; w = w->next) + for (w = priv->windows; w; w = w->next) { - if (windowOnAllViewports (w)) + if (w->onAllViewports ()) continue; - getWindowMovementForOffset (w, tx, ty, &wx, &wy); + w->getMovementForOffset (tx, ty, &wx, &wy); - if (w->saveMask & CWX) - w->saveWc.x += wx; + if (w->saveMask () & CWX) + w->saveWc ().x += wx; - if (w->saveMask & CWY) - w->saveWc.y += wy; + if (w->saveMask () & CWY) + w->saveWc ().y += wy; /* move */ - moveWindow (w, wx, wy, sync, TRUE); + w->move (wx, wy, sync, true); if (sync) - syncWindowPosition (w); + w->syncPosition (); } if (sync) { - setDesktopHints (s); + priv->setDesktopHints (); - setCurrentActiveWindowHistory (s, s->x, s->y); + setCurrentActiveWindowHistory (priv->x, priv->y); - w = findWindowAtDisplay (s->display, s->display->activeWindow); + w = priv->display->findWindow (priv->display->activeWindow ()); if (w) { int x, y; - defaultViewportForWindow (w, &x, &y); + w->defaultViewport (&x, &y); /* add window to current history if it's default viewport is still the current one. */ - if (s->x == x && s->y == y) - addToCurrentActiveWindowHistory (s, w->id); + if (priv->x == x && priv->y == y) + addToCurrentActiveWindowHistory (w->id ()); } } } -void -moveWindowToViewportPosition (CompWindow *w, - int x, - int y, - Bool sync) -{ - int tx, vWidth = w->screen->width * w->screen->hsize; - int ty, vHeight = w->screen->height * w->screen->vsize; - - if (w->screen->hsize != 1) - { - x += w->screen->x * w->screen->width; - x = MOD (x, vWidth); - x -= w->screen->x * w->screen->width; - } - - if (w->screen->vsize != 1) - { - y += w->screen->y * w->screen->height; - y = MOD (y, vHeight); - y -= w->screen->y * w->screen->height; - } - - tx = x - w->attrib.x; - ty = y - w->attrib.y; - - if (tx || ty) - { - int m, wx, wy; - - if (!w->managed) - return; - - if (w->type & (CompWindowTypeDesktopMask | CompWindowTypeDockMask)) - return; - - if (w->state & CompWindowStateStickyMask) - return; - - wx = tx; - wy = ty; - - if (w->screen->hsize != 1) - { - m = w->attrib.x + tx; - - if (m - w->output.left < w->screen->width - vWidth) - wx = tx + vWidth; - else if (m + w->width + w->output.right > vWidth) - wx = tx - vWidth; - } - - if (w->screen->vsize != 1) - { - m = w->attrib.y + ty; - - if (m - w->output.top < w->screen->height - vHeight) - wy = ty + vHeight; - else if (m + w->height + w->output.bottom > vHeight) - wy = ty - vHeight; - } - - if (w->saveMask & CWX) - w->saveWc.x += wx; - - if (w->saveMask & CWY) - w->saveWc.y += wy; - - moveWindow (w, wx, wy, sync, TRUE); - - if (sync) - syncWindowPosition (w); - } -} - CompGroup * -addGroupToScreen (CompScreen *s, - Window id) +CompScreen::addGroup (Window id) { CompGroup *group; @@ -3621,32 +3602,31 @@ addGroupToScreen (CompScreen *s, if (!group) return NULL; - group->next = s->groups; + group->next = priv->groups; group->refCnt = 1; group->id = id; - s->groups = group; + priv->groups = group; return group; } void -removeGroupFromScreen (CompScreen *s, - CompGroup *group) +CompScreen::removeGroup (CompGroup *group) { group->refCnt--; if (group->refCnt) return; - if (group == s->groups) + if (group == priv->groups) { - s->groups = group->next; + priv->groups = group->next; } else { CompGroup *g; - for (g = s->groups; g; g = g->next) + for (g = priv->groups; g; g = g->next) { if (g->next == group) { @@ -3660,12 +3640,11 @@ removeGroupFromScreen (CompScreen *s, } CompGroup * -findGroupAtScreen (CompScreen *s, - Window id) +CompScreen::findGroup (Window id) { CompGroup *g; - for (g = s->groups; g; g = g->next) + for (g = priv->groups; g; g = g->next) if (g->id == id) return g; @@ -3673,25 +3652,24 @@ findGroupAtScreen (CompScreen *s, } void -applyStartupProperties (CompScreen *screen, - CompWindow *window) +CompScreen::applyStartupProperties (CompWindow *window) { CompStartupSequence *s; - const char *startupId = window->startupId; + const char *startupId = window->startupId (); if (!startupId) { CompWindow *leader; - leader = findWindowAtScreen (screen, window->clientLeader); + leader = findWindow (window->clientLeader ()); if (leader) - startupId = leader->startupId; + startupId = leader->startupId (); if (!startupId) return; } - for (s = screen->startupSequences; s; s = s->next) + for (s = priv->startupSequences; s; s = s->next) { const char *id; @@ -3701,33 +3679,19 @@ applyStartupProperties (CompScreen *screen, } if (s) - { - int workspace; - - window->initialViewportX = s->viewportX; - window->initialViewportY = s->viewportY; - - workspace = sn_startup_sequence_get_workspace (s->sequence); - if (workspace >= 0) - window->desktop = workspace; - - window->initialTimestamp = - sn_startup_sequence_get_timestamp (s->sequence); - window->initialTimestampSet = TRUE; - } + window->applyStartupProperties (s); } void -sendWindowActivationRequest (CompScreen *s, - Window id) +CompScreen::sendWindowActivationRequest (Window id) { XEvent xev; xev.xclient.type = ClientMessage; - xev.xclient.display = s->display->display; + xev.xclient.display = priv->display->dpy (); xev.xclient.format = 32; - xev.xclient.message_type = s->display->winActiveAtom; + xev.xclient.message_type = priv->display->atoms ().winActive; xev.xclient.window = id; xev.xclient.data.l[0] = 2; @@ -3736,31 +3700,29 @@ sendWindowActivationRequest (CompScreen *s, xev.xclient.data.l[3] = 0; xev.xclient.data.l[4] = 0; - XSendEvent (s->display->display, - s->root, + XSendEvent (priv->display->dpy (), + priv->root, FALSE, SubstructureRedirectMask | SubstructureNotifyMask, &xev); } void -screenTexEnvMode (CompScreen *s, - GLenum mode) +CompScreen::setTexEnvMode (GLenum mode) { - if (s->lighting) + if (priv->lighting) glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); else glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode); } void -screenLighting (CompScreen *s, - Bool lighting) +CompScreen::setLighting (bool lighting) { - if (s->lighting != lighting) + if (priv->lighting != lighting) { - if (!s->opt[COMP_SCREEN_OPTION_LIGHTING].value.b) - lighting = FALSE; + if (!priv->opt[COMP_SCREEN_OPTION_LIGHTING].value.b) + lighting = false; if (lighting) { @@ -3773,204 +3735,190 @@ screenLighting (CompScreen *s, glDisable (GL_LIGHTING); } - s->lighting = lighting; + priv->lighting = lighting; - screenTexEnvMode (s, GL_REPLACE); + setTexEnvMode (GL_REPLACE); } } void -enableScreenEdge (CompScreen *s, - int edge) +CompScreen::enableEdge (int edge) { - s->screenEdge[edge].count++; - if (s->screenEdge[edge].count == 1) - XMapRaised (s->display->display, s->screenEdge[edge].id); + priv->screenEdge[edge].count++; + if (priv->screenEdge[edge].count == 1) + XMapRaised (priv->display->dpy (), priv->screenEdge[edge].id); } void -disableScreenEdge (CompScreen *s, - int edge) +CompScreen::disableEdge (int edge) { - s->screenEdge[edge].count--; - if (s->screenEdge[edge].count == 0) - XUnmapWindow (s->display->display, s->screenEdge[edge].id); + priv->screenEdge[edge].count--; + if (priv->screenEdge[edge].count == 0) + XUnmapWindow (priv->display->dpy (), priv->screenEdge[edge].id); } Window -getTopWindow (CompScreen *s) +CompScreen::getTopWindow () { CompWindow *w; /* return first window that has not been destroyed */ - for (w = s->reverseWindows; w; w = w->prev) + for (w = priv->reverseWindows; w; w = w->prev) { - if (w->id > 1) - return w->id; + if (w->id () > 1) + return w->id (); } return None; } void -makeScreenCurrent (CompScreen *s) +CompScreen::makeCurrent () { - if (currentRoot != s->root) + if (currentRoot != priv->root) { - glXMakeCurrent (s->display->display, s->output, s->ctx); - currentRoot = s->root; + glXMakeCurrent (priv->display->dpy (), priv->output, priv->ctx); + currentRoot = priv->root; } - s->pendingCommands = TRUE; + priv->pendingCommands = true; } void -finishScreenDrawing (CompScreen *s) +CompScreen::finishDrawing () { - if (s->pendingCommands) + if (priv->pendingCommands) { - makeScreenCurrent (s); + makeCurrent (); glFinish (); - s->pendingCommands = FALSE; + priv->pendingCommands = true; } } int -outputDeviceForPoint (CompScreen *s, - int x, - int y) +CompScreen::outputDeviceForPoint (int x, int y) { - return outputDeviceForGeometry (s, x, y, 1, 1, 0); + return outputDeviceForGeometry (x, y, 1, 1, 0); } void -getCurrentOutputExtents (CompScreen *s, - int *x1, - int *y1, - int *x2, - int *y2) +CompScreen::getCurrentOutputExtents (int *x1, int *y1, int *x2, int *y2) { if (x1) - *x1 = s->outputDev[s->currentOutputDev].region.extents.x1; + *x1 = priv->outputDev[priv->currentOutputDev].region.extents.x1; if (y1) - *y1 = s->outputDev[s->currentOutputDev].region.extents.y1; + *y1 = priv->outputDev[priv->currentOutputDev].region.extents.y1; if (x2) - *x2 = s->outputDev[s->currentOutputDev].region.extents.x2; + *x2 = priv->outputDev[priv->currentOutputDev].region.extents.x2; if (y2) - *y2 = s->outputDev[s->currentOutputDev].region.extents.y2; + *y2 = priv->outputDev[priv->currentOutputDev].region.extents.y2; } void -setNumberOfDesktops (CompScreen *s, - unsigned int nDesktop) +CompScreen::setNumberOfDesktops (unsigned int nDesktop) { CompWindow *w; if (nDesktop < 1 || nDesktop >= 0xffffffff) return; - if (nDesktop == s->nDesktop) + if (nDesktop == priv->nDesktop) return; - if (s->currentDesktop >= nDesktop) - s->currentDesktop = nDesktop - 1; + if (priv->currentDesktop >= nDesktop) + priv->currentDesktop = nDesktop - 1; - for (w = s->windows; w; w = w->next) + for (w = priv-&g |