Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Razor-qt/razor-qt
Browse files Browse the repository at this point in the history
  • Loading branch information
SokoloffA committed Oct 19, 2011
2 parents 6cd6c26 + aca4b1b commit e61b965
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 25 deletions.
37 changes: 37 additions & 0 deletions librazorqt/razorqt/xfitman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,43 @@ int XfitMan::getNumDesktop() const
}
return 0;
}

QStringList XfitMan::getDesktopNames() const
{
QStringList ret;
unsigned long length;
unsigned char *data = 0;

if (getRootWindowProperty(atom("_NET_DESKTOP_NAMES"), atom("UTF8_STRING"), &length, &data))
{
if (data)
{
char* c = (char*)data;
char* end = (char*)data + length;
while (c < end)
{
ret << QString::fromUtf8(c);
c += strlen(c) + 1; // for trailing \0
}

XFree(data);
}
}


return ret;
}


QString XfitMan::getDesktopName(int desktopNum, const QString &defaultName) const
{
QStringList names = getDesktopNames();
if (desktopNum<0 || desktopNum>names.count()-1)
return defaultName;

return names.at(desktopNum);
}

/**
* @brief resizes a window to the given dimensions
*/
Expand Down
16 changes: 16 additions & 0 deletions librazorqt/razorqt/xfitman.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ class XfitMan
Window getActiveAppWindow() const;
Window getActiveWindow() const;
int getNumDesktop() const;

/*!
* Returns the names of all virtual desktops. This is a list of UTF-8 encoding strings.
*
* Note: The number of names could be different from getNumDesktop(). If it is less
* than getNumDesktop(), then the desktops with high numbers are unnamed. If it is
* larger than getNumDesktop(), then the excess names outside of the getNumDesktop()
* are considered to be reserved in case the number of desktops is increased.
*/
QStringList getDesktopNames() const;

/*!
* Returns the name of virtual desktop.
*/
QString getDesktopName(int desktopNum, const QString &defaultName=QString()) const;

QString getName(Window _wid) const;

bool acceptWindow(Window _wid) const;
Expand Down
2 changes: 2 additions & 0 deletions razorqt-appswitcher/src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
* END_COMMON_COPYRIGHT_HEADER */

#include "razorqt/razorsettings.h"
#include <qtxdg/xdgicon.h>
#include "application.h"


RazorAppSwitcher::Application::Application(int & argc, char ** argv)
: QApplication(argc, argv),
m_as(0)
{
XdgIcon::setThemeName(RazorSettings::globalSettings()->value("icon_theme").toString());
setStyleSheet(razorTheme->qss("appswitcher"));

m_as = new RazorAppSwitcher::AppSwitcher();
Expand Down
3 changes: 3 additions & 0 deletions razorqt-config/razor-config-appearance/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@

#include <QApplication>

#include <qtxdg/xdgicon.h>
#include <razorqt/razorsettings.h>
#include "mainwindow.h"
#include "razortranslate.h"

int main (int argc, char **argv)
{
QApplication app(argc, argv);
XdgIcon::setThemeName(RazorSettings::globalSettings()->value("icon_theme").toString());
app.setWindowIcon(QIcon(QString(SHARE_DIR) + "/graphics/razor_logo.png"));
TRANSLATE_APP;

Expand Down
3 changes: 3 additions & 0 deletions razorqt-config/razor-config-mouse/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
//#include <QtCore>
#include <QDebug>

#include <qtxdg/xdgicon.h>
#include <razorqt/razorsettings.h>
#include "main.h"

#include <QApplication>
Expand All @@ -26,6 +28,7 @@ int main (int argc, char *argv[]) {
// QTextCodec::setCodecForLocale(QTextCodec::codecForName("koi8-r"));

QApplication app(argc, argv);
XdgIcon::setThemeName(RazorSettings::globalSettings()->value("icon_theme").toString());
app.setWindowIcon(QIcon(QString(SHARE_DIR) + "/graphics/razor_logo.png"));

//qDebug() << findDefaultTheme() << getCurrentTheme();
Expand Down
3 changes: 3 additions & 0 deletions razorqt-config/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
#include <QtGui/QApplication>
#include <QtGui/QIcon>

#include <qtxdg/xdgicon.h>
#include <razorqt/razorsettings.h>
#include "mainwindow.h"


int main(int argc, char **argv)
{
QApplication app(argc, argv);
XdgIcon::setThemeName(RazorSettings::globalSettings()->value("icon_theme").toString());
app.setWindowIcon(QIcon(QString(SHARE_DIR) + "/graphics/razor_logo.png"));

RazorConfig::MainWindow w;
Expand Down
4 changes: 2 additions & 2 deletions razorqt-desktop/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
#include <QIcon>

#include <razorqt/razorsettings.h>
#include <qtxdg/xdgicon.h>
#include "desktopplugin.h"



int main (int argc, char* argv[])
{
//TODO make singleton QApplication that does all this shit, then make razorsettings and stylesettings available and fix all the other stuff with it

QApplication app(argc,argv);
XdgIcon::setThemeName(RazorSettings::globalSettings()->value("icon_theme").toString());
app.setWindowIcon(QIcon(QString(SHARE_DIR) + "/graphics/razor_logo.png"));

RazorSettings config("desktop");
Expand Down
3 changes: 3 additions & 0 deletions razorqt-panel/plugin-desktopswitch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ set(PLUGIN "desktopswitch")

set(HEADERS
desktopswitch.h
desktopswitchbutton.h
)

set(SOURCES
desktopswitch.cpp
desktopswitchbutton.cpp
)

set(MOCS
desktopswitch.h
desktopswitchbutton.h
)

set(LIBRARIES ${LIBRARIES} ${CMAKE_BINARY_DIR}/librazorqt/librazorqxt.so )
Expand Down
70 changes: 50 additions & 20 deletions razorqt-panel/plugin-desktopswitch/desktopswitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,55 @@
#include <razorqt/xfitman.h>
#include <razorqxt/qxtglobalshortcut.h>


#include "desktopswitch.h"
#include "desktopswitchbutton.h"


EXPORT_RAZOR_PANEL_PLUGIN_CPP(DesktopSwitch)


DesktopSwitch::DesktopSwitch(const RazorPanelPluginStartInfo* startInfo, QWidget* parent)
: RazorPanelPlugin(startInfo, parent),
m_pSignalMapper(new QSignalMapper(this))
m_pSignalMapper(new QSignalMapper(this)),
m_desktopCount(1)
{
setObjectName("DesktopSwitch");
m_buttons = new QButtonGroup(this);

connect ( m_pSignalMapper, SIGNAL(mapped(int)), this, SLOT(setDesktop(int)));

QString mask("%1");
int numDesk = qMax(xfitMan().getNumDesktop(), 1);
int firstKey = Qt::Key_F1 ;
for (int i = 0; i < numDesk; ++i)
setup();
}

void DesktopSwitch::setup()
{
// clear current state
foreach (QAbstractButton * b, m_buttons->buttons())
{
QxtGlobalShortcut * pS = new QxtGlobalShortcut(this);
pS ->setShortcut(QKeySequence(Qt::CTRL + firstKey++));

connect ( pS, SIGNAL(activated()), m_pSignalMapper, SLOT(map())) ;
m_pSignalMapper->setMapping( pS, i);

QToolButton * m = new QToolButton(this);
m->setText(mask.arg(i+1));
m->setCheckable(true);
// TODO/FIXME: maybe it has to be removed from layout too?
m_pSignalMapper->removeMappings(b);
m_buttons->removeButton(b);
delete b;
}

// create new desktop layout
int firstKey = Qt::Key_F1;
int maxKey = Qt::Key_F35; // max defined in Qt

for (int i = 0; i < m_desktopCount; ++i)
{
QKeySequence sequence;
if (firstKey < maxKey)
{
sequence = QKeySequence(Qt::CTRL + firstKey++);
}

DesktopSwitchButton * m = new DesktopSwitchButton(this, i, sequence, xfitMan().getDesktopName(i, tr("Desktop %1").arg(i+1)));
m_pSignalMapper->setMapping(m, i);
connect(m, SIGNAL(activated()), m_pSignalMapper, SLOT(map())) ;
addWidget(m);
m_buttons->addButton(m, i);
}

connect ( m_pSignalMapper, SIGNAL(mapped(int)), this, SLOT(setDesktop(int)));


int activeDesk = qMax(xfitMan().getActiveDesktop(), 0);
m_buttons->button(activeDesk)->setChecked(true);
Expand All @@ -81,6 +98,21 @@ void DesktopSwitch::x11EventFilter(XEvent* _event)
{
if (_event->type == PropertyNotify)
{
int count = qMax(xfitMan().getNumDesktop(), 1);
if (m_desktopCount != count)
{
qDebug() << "Desktop count changed from" << m_desktopCount << "to" << count;
m_desktopCount = count;
m_desktopNames = xfitMan().getDesktopNames();
setup();
}

if (m_desktopNames != xfitMan().getDesktopNames())
{
m_desktopNames = xfitMan().getDesktopNames();
setup();
}

int activeDesk = qMax(xfitMan().getActiveDesktop(), 0);
m_buttons->button(activeDesk)->setChecked(true);
}
Expand All @@ -103,5 +135,3 @@ void DesktopSwitch::wheelEvent(QWheelEvent* e)

xfitMan().setActiveDesktop(current);
}


8 changes: 5 additions & 3 deletions razorqt-panel/plugin-desktopswitch/desktopswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class QSignalMapper;
class QButtonGroup;


/**
* @brief Desktop switcher. A very simple one...
*/
Expand All @@ -47,14 +48,15 @@ class DesktopSwitch : public RazorPanelPlugin

private:
QButtonGroup * m_buttons;
QSignalMapper* m_pSignalMapper ;
QSignalMapper* m_pSignalMapper;
int m_desktopCount;
QStringList m_desktopNames;

void wheelEvent(QWheelEvent* e);
void setup();

private slots:
void setDesktop(int desktop);


};


Expand Down
52 changes: 52 additions & 0 deletions razorqt-panel/plugin-desktopswitch/desktopswitchbutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* BEGIN_COMMON_COPYRIGHT_HEADER
*
* Razor - a lightweight, Qt based, desktop toolset
* http://razor-qt.org
*
* Copyright: 2011 Razor team
* Authors:
* Petr Vanek <petr@scribus.info>
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */


#include <QToolButton>
#include <QtDebug>
#include <razorqxt/qxtglobalshortcut.h>

#include "desktopswitchbutton.h"

DesktopSwitchButton::DesktopSwitchButton(QWidget * parent, int index, const QKeySequence &sequence, const QString &title)
: QToolButton(parent)
{
QString mask("%1");
setText(mask.arg(index+1));
setCheckable(true);

if (!sequence.isEmpty())
{
m_shortcut = new QxtGlobalShortcut(this);
m_shortcut->setShortcut(sequence);
connect(m_shortcut, SIGNAL(activated()), this, SIGNAL(activated()));
}

if (!title.isEmpty())
{
setToolTip(title);
}
}
49 changes: 49 additions & 0 deletions razorqt-panel/plugin-desktopswitch/desktopswitchbutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* BEGIN_COMMON_COPYRIGHT_HEADER
*
* Razor - a lightweight, Qt based, desktop toolset
* http://razor-qt.org
*
* Copyright: 2011 Razor team
* Authors:
* Petr Vanek <petr@scribus.info>
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */


#ifndef DESKTOPSWITCHBUTTON_H
#define DESKTOPSWITCHBUTTON_H

#include <QtGui/QToolButton>

class QxtGlobalShortcut;

class DesktopSwitchButton : public QToolButton
{
Q_OBJECT

public:
DesktopSwitchButton(QWidget * parent, int index, const QKeySequence &sequence, const QString &title=QString());

signals:
void activated();

private:
QxtGlobalShortcut * m_shortcut;
};

#endif

0 comments on commit e61b965

Please sign in to comment.