aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/ServerAutoApp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbcompose/ServerAutoApp.cc')
-rw-r--r--util/fbcompose/ServerAutoApp.cc143
1 files changed, 143 insertions, 0 deletions
diff --git a/util/fbcompose/ServerAutoApp.cc b/util/fbcompose/ServerAutoApp.cc
new file mode 100644
index 0000000..1f42575
--- /dev/null
+++ b/util/fbcompose/ServerAutoApp.cc
@@ -0,0 +1,143 @@
1/** ServerAutoApp.cc file for the fluxbox compositor. */
2
3// Copyright (c) 2011 Gediminas Liktaras (gliktaras at gmail dot com)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21// THE SOFTWARE.
22
23
24#ifdef HAVE_CONFIG_H
25 #include "config.h"
26#endif // HAVE_CONFIG_H
27
28#include "ServerAutoApp.hh"
29
30#include "Atoms.hh"
31#include "CompositorConfig.hh"
32#include "Constants.hh"
33
34#include <X11/extensions/Xcomposite.h>
35#include <X11/Xlib.h>
36#include <X11/Xutil.h>
37
38#include <sstream>
39
40#ifdef HAVE_CTIME
41 #include <ctime>
42#else
43#ifdef HAVE_TIME_H
44 #include <time.h>
45#endif // HAVE_TIME_H
46#endif // HAVE_CTIME
47
48#include <csignal>
49
50using namespace FbCompositor;
51
52
53//--- CONSTANTS ----------------------------------------------------------------
54
55// How many microseconds to sleep before restarting the event loop.
56const int SLEEP_TIME = 10000;
57
58
59//--- CONSTRUCTORS AND DESTRUCTORS ---------------------------------------------
60
61// Constructor.
62ServerAutoApp::ServerAutoApp(const CompositorConfig &config) :
63 App(config.displayName().c_str()) {
64
65 if (config.renderingMode() != RM_ServerAuto) {
66 throw InitException("ServerAutoApp provides only the \"serverauto\" renderer.");
67 }
68 initComposite();
69 initScreens();
70
71 XFlush(display());
72
73 signal(SIGINT, handleSignal_ServerAuto);
74 signal(SIGTERM, handleSignal_ServerAuto);
75}
76
77// Destructor.
78ServerAutoApp::~ServerAutoApp() { }
79
80
81//--- INITIALIZATION FUNCTIONS -------------------------------------------------
82
83// Initialize Composite extension.
84void ServerAutoApp::initComposite() {
85 int event_base;
86 int error_base;
87 int major_ver;
88 int minor_ver;
89
90 if (!XCompositeQueryExtension(display(), &event_base, &error_base)) {
91 throw InitException("Composite extension not found.");
92 }
93 if (!XCompositeQueryVersion(display(), &major_ver, &minor_ver)) {
94 throw InitException("Could not query the version of the Composite extension.");
95 }
96 if ((major_ver < 0) || ((major_ver == 0) && (minor_ver < 1))) {
97 std::stringstream ss;
98 ss << "Unsupported Composite extension version found (required >=0.1, got "
99 << major_ver << "." << minor_ver << ").";
100 throw InitException(ss.str());
101 }
102}
103
104// Prepare screens.
105void ServerAutoApp::initScreens() {
106 int screen_count = XScreenCount(display());
107
108 for (int i = 0; i < screen_count; i++) {
109 XCompositeRedirectSubwindows(display(), XRootWindow(display(), i), CompositeRedirectAutomatic);
110
111 Atom cm_atom = Atoms::compositingSelectionAtom(i);
112 Window cur_owner = XGetSelectionOwner(display(), cm_atom);
113 if (cur_owner != None) {
114 // TODO: More detailed message - what is the other program?
115 throw InitException("Another compositing manager is running.");
116 }
117
118 cur_owner = XCreateSimpleWindow(display(), XRootWindow(display(), i), -10, -10, 1, 1, 0, None, None);
119 XmbSetWMProperties(display(), cur_owner, APP_NAME, APP_NAME, NULL, 0, NULL, NULL, NULL);
120 XSetSelectionOwner(display(), cm_atom, cur_owner, CurrentTime);
121 }
122}
123
124
125//--- EVENT LOOP ---------------------------------------------------------------
126
127// Enters the event loop.
128void ServerAutoApp::eventLoop() {
129 timespec sleep_timespec = { 0, SLEEP_TIME * 1000 };
130 while (!done()) {
131 nanosleep(&sleep_timespec, NULL);
132 }
133}
134
135
136//--- VARIOUS HANDLERS ---------------------------------------------------------
137
138// Custom signal handler for ServerAuto mode.
139void FbCompositor::handleSignal_ServerAuto(int sig) {
140 if ((sig == SIGINT) || (sig == SIGTERM)) {
141 FbTk::App::instance()->end();
142 }
143}