-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathwindow_manager.hpp
85 lines (74 loc) · 2.97 KB
/
window_manager.hpp
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
#ifndef WINDOW_MANAGER_HPP
#define WINDOW_MANAGER_HPP
extern "C" {
#include <X11/Xlib.h>
}
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include "util.hpp"
// Implementation of a window manager for an X screen.
class WindowManager {
public:
// Creates a WindowManager instance for the X display/screen specified by the
// argument string, or if unspecified, the DISPLAY environment variable. On
// failure, returns nullptr.
static ::std::unique_ptr<WindowManager> Create(
const std::string& display_str = std::string());
~WindowManager();
// The entry point to this class. Enters the main event loop.
void Run();
private:
// Invoked internally by Create().
WindowManager(Display* display);
// Frames a top-level window.
void Frame(Window w, bool was_created_before_window_manager);
// Unframes a client window.
void Unframe(Window w);
// Event handlers.
void OnCreateNotify(const XCreateWindowEvent& e);
void OnDestroyNotify(const XDestroyWindowEvent& e);
void OnReparentNotify(const XReparentEvent& e);
void OnMapNotify(const XMapEvent& e);
void OnUnmapNotify(const XUnmapEvent& e);
void OnConfigureNotify(const XConfigureEvent& e);
void OnMapRequest(const XMapRequestEvent& e);
void OnConfigureRequest(const XConfigureRequestEvent& e);
void OnButtonPress(const XButtonEvent& e);
void OnButtonRelease(const XButtonEvent& e);
void OnMotionNotify(const XMotionEvent& e);
void OnKeyPress(const XKeyEvent& e);
void OnKeyRelease(const XKeyEvent& e);
// Xlib error handler. It must be static as its address is passed to Xlib.
static int OnXError(Display* display, XErrorEvent* e);
// Xlib error handler used to determine whether another window manager is
// running. It is set as the error handler right before selecting substructure
// redirection mask on the root window, so it is invoked if and only if
// another window manager is running. It must be static as its address is
// passed to Xlib.
static int OnWMDetected(Display* display, XErrorEvent* e);
// Whether an existing window manager has been detected. Set by OnWMDetected,
// and hence must be static.
static bool wm_detected_;
// A mutex for protecting wm_detected_. It's not strictly speaking needed as
// this program is single threaded, but better safe than sorry.
static ::std::mutex wm_detected_mutex_;
// Handle to the underlying Xlib Display struct.
Display* display_;
// Handle to root window.
const Window root_;
// Maps top-level windows to their frame windows.
::std::unordered_map<Window, Window> clients_;
// The cursor position at the start of a window move/resize.
Position<int> drag_start_pos_;
// The position of the affected window at the start of a window
// move/resize.
Position<int> drag_start_frame_pos_;
// The size of the affected window at the start of a window move/resize.
Size<int> drag_start_frame_size_;
// Atom constants.
const Atom WM_PROTOCOLS;
const Atom WM_DELETE_WINDOW;
};
#endif