2
* This file is part of unity-2d
4
* Copyright 2010 Canonical Ltd.
7
* - Olivier Tilloy <olivier.tilloy@canonical.com>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; version 3.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>
23
#include "panelmanager.h"
29
#include <appindicator/appindicatorapplet.h>
30
#include <appname/appnameapplet.h>
31
#include <homebutton/homebuttonapplet.h>
32
#include <indicator/indicatorapplet.h>
33
#include <legacytray/legacytrayapplet.h>
36
#include <unity2dpanel.h>
39
#include <QApplication>
40
#include <QDesktopWidget>
43
using namespace Unity2d;
45
static QPalette getPalette()
49
/* Should use the panel's background provided by Unity but it turns
50
out not to be good. It would look like:
52
QBrush bg(QPixmap("theme:/panel_background.png"));
54
QBrush bg(QPixmap(unity2dDirectory() + "/panel/artwork/background.png"));
55
palette.setBrush(QPalette::Window, bg);
56
palette.setBrush(QPalette::Button, bg);
57
palette.setColor(QPalette::WindowText, Qt::white);
58
palette.setColor(QPalette::ButtonText, Qt::white);
62
static QLabel* createSeparator()
64
QLabel* label = new QLabel;
65
QPixmap pix(unity2dDirectory() + "/panel/artwork/divider.png");
66
label->setPixmap(pix);
67
label->setFixedSize(pix.size());
71
static Unity2dPanel* instantiatePanel(int screen)
73
Unity2dPanel* panel = new Unity2dPanel;
74
panel->setEdge(Unity2dPanel::TopEdge);
75
panel->setPalette(getPalette());
76
panel->setFixedHeight(24);
78
int primary = QApplication::desktop()->primaryScreen();
79
if (screen == primary) {
80
panel->addWidget(new HomeButtonApplet);
81
panel->addWidget(createSeparator());
83
panel->addWidget(new AppNameApplet);
84
if (screen == primary) {
85
/* It doesn’t make sense to have more than one instance of the systray,
86
XEmbed’ed windows can be displayed only once anyway. */
87
panel->addWidget(new LegacyTrayApplet);
89
panel->addWidget(new IndicatorApplet);
93
PanelManager::PanelManager(QObject* parent)
96
QDesktopWidget* desktop = QApplication::desktop();
97
for(int i = 0; i < desktop->screenCount(); ++i) {
98
Unity2dPanel* panel = instantiatePanel(i);
99
m_panels.append(panel);
101
panel->move(desktop->screenGeometry(i).topLeft());
103
connect(desktop, SIGNAL(screenCountChanged(int)), SLOT(onScreenCountChanged(int)));
106
PanelManager::~PanelManager()
108
qDeleteAll(m_panels);
112
PanelManager::onScreenCountChanged(int newCount)
114
QDesktopWidget* desktop = QApplication::desktop();
115
int size = m_panels.size();
116
/* Update the position of existing panels, and instantiate new panels. */
117
for (int i = 0; i < newCount; ++i) {
122
panel = instantiatePanel(i);
123
m_panels.append(panel);
126
panel->move(desktop->screenGeometry(i).topLeft());
128
/* Remove extra panels if any. */
129
while (m_panels.size() > newCount) {
130
delete m_panels.takeLast();
134
#include "panelmanager.moc"