1 #include "layouthandler.h"
3 LayoutHandler::LayoutHandler(QObject *parent) :
5 mp_dBusWindowManagerProxy(0),
9 m_requestsToBeVisibleApps()
11 qDBusRegisterMetaType<SimplePoint>();
12 qDBusRegisterMetaType<QList<SimplePoint> >();
13 qDBusRegisterMetaType<SimpleRect>();
14 qDBusRegisterMetaType<QList<SimpleRect> >();
16 qDebug("D-Bus: connect to org.agl.windowmanager /windowmanager");
17 mp_dBusWindowManagerProxy = new org::agl::windowmanager("org.agl.windowmanager",
19 QDBusConnection::sessionBus(),
21 qDebug("D-Bus: connect to org.agl.homescreen /Popup");
22 mp_dBusPopupProxy = new org::agl::popup("org.agl.homescreen",
24 QDBusConnection::sessionBus(),
28 LayoutHandler::~LayoutHandler()
30 delete mp_dBusPopupProxy;
31 delete mp_dBusWindowManagerProxy;
34 void LayoutHandler::setUpLayouts()
36 qDebug("setUpLayouts");
37 QList<SimpleRect> surfaceAreas;
38 SimpleRect surfaceArea;
40 int associatedFullScreenLayout;
42 const int SCREEN_WIDTH = 1080;
43 const int SCREEN_HEIGHT = 1920;
45 const int STATUSBAR_HEIGHT = 60;
46 const int STATUSBAR_WIDTH = SCREEN_WIDTH;
47 const int STATUSBAR_X = 0;
48 const int STATUSBAR_Y = 0;
49 const int CONTROLBAR_HEIGHT = 60;
50 const int CONTROLBAR_WIDTH = SCREEN_WIDTH;
51 const int CONTROLBAR_X = 0;
52 const int CONTROLBAR_Y = SCREEN_HEIGHT - CONTROLBAR_HEIGHT;
56 // one app surface, statusbar, control bar
58 surfaceArea.y = STATUSBAR_HEIGHT;
59 surfaceArea.width = SCREEN_WIDTH;
60 surfaceArea.height = SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT;
62 surfaceAreas.append(surfaceArea);
65 associatedFullScreenLayout = 4;
67 mp_dBusWindowManagerProxy->addLayout(1, "one app", isFullScreen, associatedFullScreenLayout, surfaceAreas);
73 // two app surfaces (one on top of the other), statusbar, control bar
77 surfaceArea.y = STATUSBAR_HEIGHT;
78 surfaceArea.width = SCREEN_WIDTH;
79 surfaceArea.height = (SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT) / 2;
81 surfaceAreas.append(surfaceArea);
85 surfaceArea.y = SCREEN_HEIGHT / 2;
86 surfaceArea.width = SCREEN_WIDTH;
87 surfaceArea.height = (SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT) / 2;
89 surfaceAreas.append(surfaceArea);
92 associatedFullScreenLayout = -1;
94 mp_dBusWindowManagerProxy->addLayout(2, "top on bottom", isFullScreen, associatedFullScreenLayout, surfaceAreas);
100 // two app surfaces (one besides the other), statusbar, control bar
104 surfaceArea.y = STATUSBAR_HEIGHT;
105 surfaceArea.width = SCREEN_WIDTH / 2;
106 surfaceArea.height = SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT;
108 surfaceAreas.append(surfaceArea);
111 surfaceArea.x = SCREEN_WIDTH / 2;
112 surfaceArea.y = STATUSBAR_HEIGHT;
113 surfaceArea.width = SCREEN_WIDTH / 2;
114 surfaceArea.height = SCREEN_HEIGHT - STATUSBAR_HEIGHT - CONTROLBAR_HEIGHT;
116 surfaceAreas.append(surfaceArea);
118 isFullScreen = false;
119 associatedFullScreenLayout = -1;
121 mp_dBusWindowManagerProxy->addLayout(3, "side by side", isFullScreen, associatedFullScreenLayout, surfaceAreas);
124 surfaceAreas.clear();
127 // one app surface full screen, no statusbar, no control bar
130 surfaceArea.width = SCREEN_WIDTH;
131 surfaceArea.height = SCREEN_HEIGHT;
133 surfaceAreas.append(surfaceArea);
136 associatedFullScreenLayout = 1;
138 mp_dBusWindowManagerProxy->addLayout(4, "one app full screen", isFullScreen, associatedFullScreenLayout, surfaceAreas);
141 surfaceAreas.clear();
145 void LayoutHandler::makeMeVisible(int pid)
147 qDebug("makeMeVisible %d", pid);
148 m_requestsToBeVisibleApps.append(pid);
150 qDebug("m_visibleApps %d", m_visibleApps.size());
151 qDebug("m_invisibleApps %d", m_invisibleApps.size());
152 qDebug("m_requestsToBeVisibleApps %d", m_requestsToBeVisibleApps.size());
154 QList<int> availableLayouts = mp_dBusWindowManagerProxy->getAvailableLayouts(m_visibleApps.size() + m_requestsToBeVisibleApps.size());
155 if (0 == availableLayouts.size())
157 // no layout fits the need!
158 // replace the last app
159 qDebug("no layout fits the need!");
160 qDebug("replace the last app");
162 m_invisibleApps.append(m_visibleApps.last());
163 m_visibleApps.removeLast();
165 m_visibleApps.append(m_requestsToBeVisibleApps);
166 m_requestsToBeVisibleApps.clear();
168 for (int i = 0; i < m_visibleApps.size(); ++i)
170 mp_dBusWindowManagerProxy->setPidToLayoutArea(m_visibleApps.at(i), i);
173 if (1 == availableLayouts.size())
175 // switch to new layout
176 qDebug("switch to new layout %d", availableLayouts.at(0));
177 m_visibleApps.append(m_requestsToBeVisibleApps);
178 m_requestsToBeVisibleApps.clear();
180 mp_dBusWindowManagerProxy->setLayoutById(availableLayouts.at(0));
181 for (int i = 0; i < m_visibleApps.size(); ++i)
183 mp_dBusWindowManagerProxy->setPidToLayoutArea(m_visibleApps.at(i), i);
186 if (1 < availableLayouts.size())
188 // more than one layout possible! Ask user.
189 qDebug("more than one layout possible! Ask user.");
192 for (int i = 0; i < availableLayouts.size(); ++i)
194 choices.append(mp_dBusWindowManagerProxy->getLayoutName(availableLayouts.at(i)));
197 mp_dBusPopupProxy->showPopupComboBox("Select Layout", choices);
202 void LayoutHandler::toggleFullscreen()
204 qDebug("toggleFullscreen");
205 int currentLayout = mp_dBusWindowManagerProxy->getLayout();
206 int associatedFullScreenLayout = mp_dBusWindowManagerProxy->getAssociatedFullScreenLayout(currentLayout);
207 if (-1 != associatedFullScreenLayout)
209 mp_dBusWindowManagerProxy->setLayoutById(associatedFullScreenLayout);
210 for (int i = 0; i < m_visibleApps.size(); ++i)
212 mp_dBusWindowManagerProxy->setPidToLayoutArea(m_visibleApps.at(i), i);
217 qDebug("no associatedFullScreenLayout. Cannot switch to full screen.");
221 void LayoutHandler::setLayoutByName(QString layoutName)
223 // switch to new layout
224 qDebug("setLayout: switch to new layout %s", layoutName.toStdString().c_str());
225 m_visibleApps.append(m_requestsToBeVisibleApps);
226 m_requestsToBeVisibleApps.clear();
228 mp_dBusWindowManagerProxy->setLayoutByName(layoutName);
229 for (int i = 0; i < m_visibleApps.size(); ++i)
231 mp_dBusWindowManagerProxy->setPidToLayoutArea(i, i);