summaryrefslogtreecommitdiff
path: root/src/WMWindow.h
blob: 82760fb242dfac4bbfcffd7681bd2da1f7ca5d4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* $Id: WMWindow.h,v 1.19 2007/01/07 05:00:56 whot Exp $ */

/*--
  --*/

#ifndef __WMWINDOW_H__
#define __WMWINDOW_H__

#include<X11/Xlib.h>
#include<X11/Xatom.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include "logger.h"
#include "Config.h"
#include "Manager.h"
#include "Process.h"
#include "XConn.h"
#include <cairo.h>

using namespace std;

class Manager;
class PointerDevice;
class Process;

/**
 * Describes a top-level window. A window consists of a container (with the
 * root window as parent) and several child windows (the actual client's
 * window and whatever the window manager added).  
 */
class WMWindow
{
    private:
        Manager* manager;
        XConn* x11;

        Process* process;

        /* X11 windows used for the client's window. */
        Window container; // container window, parent of all others
        GC containerGC;
        Window client; // the actual client's window
        Window windowBar; // window manager top bar
        GC windowBarGC;
        Window resizeBar; // the bottom bar. Holds resizeSE and resizeSW.

        Window resizeBtNE; // resize button north-east 
        Window resizeBtSE; // resize button south-east 
        Window resizeBtNW; // resize button north-west 
        Window resizeBtSW; // resize button south-west
        Window btClose; // close window button
        Window btOwner; // ownership button
        Window btMinimize; // minimize button

        /* Pixmaps for back buffering */
        Pixmap pxContainer; 

        Window resizeWin; // overlay during resizing

        int clientOffset; // x offset of client
        int width; // width of container window
        int height; // height of container window
        int x; // x coordinate of container window relative to root window
        int y; // y coordinate of container window relative to root window

        int state;
        int override_redirect;

        bool minimized;
        bool resizing;

        PointerDevice* controller; // the device in control of the window
        PointerDevice* restrictedTo; // the device allowed to access the window
        vector<PointerDevice*> resizers; // devices that resizes the window ATM

        bool exception; // used to indicate a failed startup.

    private:
        void paintWindowBar();
        void paintButton(cairo_t* cr);

    public:
        WMWindow(Manager* manager, Window client_window, XConn* x11);
        ~WMWindow();
        bool hasWindow(Window window); 
        bool isWindowBar(Window window);
        bool isResizeButton(Window window);
        bool isResizeBar(Window window);
        bool isButtonClose(Window window);
        bool isButtonMinimize(Window window);
        bool isContainer(Window window);
        bool isClientWindow(Window window);
        bool onPosition(int x, int y);

        int getX() { return x; }
        int getY() { return y; }
        int getWidth() { return width; }
        int getHeight() { return height; }

        void decorate();
        void reconfigure(XConfigureRequestEvent* ev);
        void manage();
        void move(int x, int y);
        void setResizeInProgress(bool on);
        void resize(int width, int height);
        void resizeDirected(Window button, int width, int height);
        void resizeAbsolute(int x, int y, int width, int height);
        void mapAll();
        void raise();

        int getState() { return state; }
        void setState(int s) { state = s; }

        bool setController(PointerDevice* dev);
        void releaseController() { controller = NULL; }
        bool addResizer(PointerDevice* dev);
        void releaseResizer(PointerDevice* dev);

        Window getWindowBar() { return windowBar; }
        Window getResizeBar() { return resizeBar; }
        Window getButtonClose() { return btClose; }
        Window getButtonMinimize() { return btMinimize; }
        Window getClientWindow() { return client; }
        Window getContainer() { return container; }

        Window getResizeBtNE() { return resizeBtNE; }
        Window getResizeBtSE() { return resizeBtSE; }
        Window getResizeBtNW() { return resizeBtNW; }
        Window getResizeBtSW() { return resizeBtSW; }

        bool isResizing() { return resizing; }

        void suggestDestruction();
        void destroy();
        void expose(XExposeEvent* event);
        void setMinimize(bool minimize);

        bool restrictTo(PointerDevice* dev);
        bool isLocked() { return (restrictedTo != NULL); }
        bool release(PointerDevice* dev);

        void cancel() { exception = true; } // to cancel constructor

        void extractPID();

        void changeOwnership(PointerDevice* dev);
        void recolor();

        void handleEnterLeaveNotify(XCrossingEvent* ev);

        friend class Manager;
};

#endif