Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Panel Keyboard indicator plugin - Done

  • Loading branch information...
commit 117ca70b7f2072b7badf1af9deb1a81ca92941cb 1 parent a867f27
Kuzma Shapran kuzmas authored amoskvin committed
3  razorqt-panel/plugin-kbindicator/CMakeLists.txt
View
@@ -5,16 +5,19 @@ set(PLUGIN "panelkbindicator")
set(HEADERS
razorkbindicator.h
+ razorkbindicatoreventfilter.h
razorkbindicatorconfiguration.h
)
set(SOURCES
razorkbindicator.cpp
+ razorkbindicatoreventfilter.cpp
razorkbindicatorconfiguration.cpp
)
set(MOCS
razorkbindicator.h
+ razorkbindicatoreventfilter.h
razorkbindicatorconfiguration.h
)
23 razorqt-panel/plugin-kbindicator/razorkbindicator.cpp
View
@@ -29,21 +29,25 @@
#include <QtGui/QLabel>
+#include "razorkbindicatoreventfilter.h"
+
EXPORT_RAZOR_PANEL_PLUGIN_CPP(RazorKbIndicator)
+
RazorKbIndicator::RazorKbIndicator(const RazorPanelPluginStartInfo *startInfo, QWidget *parent):
RazorPanelPlugin(startInfo, parent),
- content(new QLabel(this))
+ content(new QLabel(this)),
+ eventFilter(RazorKbIndicatorEventFilter::instance())
{
setObjectName("KbIndicator");
- addWidget(content);
+ connect(eventFilter, SIGNAL(indicatorsChanged(uint,uint)), this, SLOT(setIndicators(uint,uint)));
- this->layout()->setContentsMargins(0, 0, 0, 0);
- this->layout()->setSpacing(0);
+ addWidget(content);
settingsChanged();
+ content->setEnabled(eventFilter->getLockStatus(bit));
}
RazorKbIndicator::~RazorKbIndicator()
@@ -54,8 +58,7 @@ void RazorKbIndicator::settingsChanged()
{
bit = settings().value("bit", 0).toInt();
content->setText(settings().value("text", QString("C")).toString());
-
- update();
+ content->setEnabled(eventFilter->getLockStatus(bit));
}
void RazorKbIndicator::showConfigureDialog()
@@ -63,11 +66,15 @@ void RazorKbIndicator::showConfigureDialog()
RazorKbIndicatorConfiguration *confWindow = this->findChild<RazorKbIndicatorConfiguration*>("KbIndicatorConfigurationWindow");
if (!confWindow)
- {
confWindow = new RazorKbIndicatorConfiguration(settings(), this);
- }
confWindow->show();
confWindow->raise();
confWindow->activateWindow();
}
+
+void RazorKbIndicator::setIndicators(unsigned int changed, unsigned int state)
+{
+ if (changed & (1 << bit))
+ content->setEnabled(state & (1 << bit));
+}
10 razorqt-panel/plugin-kbindicator/razorkbindicator.h
View
@@ -33,10 +33,7 @@
class QLabel;
-
-namespace KbIndicator {
- class BaseStat;
-}
+class RazorKbIndicatorEventFilter;
class RazorKbIndicator : public RazorPanelPlugin
{
@@ -51,13 +48,14 @@ protected slots:
virtual void settingsChanged();
virtual void showConfigureDialog();
-protected:
-// void paintEvent(QPaintEvent *);
+ void setIndicators(unsigned int, unsigned int);
private:
QLabel *content;
int bit;
+
+ RazorKbIndicatorEventFilter *eventFilter;
};
2  razorqt-panel/plugin-kbindicator/razorkbindicatorconfiguration.ui
View
@@ -70,7 +70,7 @@
<number>0</number>
</property>
<property name="maximum">
- <number>15</number>
+ <number>31</number>
</property>
</widget>
</item>
103 razorqt-panel/plugin-kbindicator/razorkbindicatoreventfilter.cpp
View
@@ -0,0 +1,103 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Kuzma Shapran <kuzma.shapran@gmail.com>
+ *
+ * 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 2.1 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 "razorkbindicatoreventfilter.h"
+
+#include <X11/XKBlib.h>
+
+
+static RazorKbIndicatorEventFilter *filterObject = NULL;
+
+
+bool X11_eventFilter(void *message)
+{
+ return filterObject ? filterObject->X11_eventFilter(message) : false;
+}
+
+RazorKbIndicatorEventFilter* RazorKbIndicatorEventFilter::instance(void)
+{
+ if (!filterObject)
+ new RazorKbIndicatorEventFilter();
+ return filterObject;
+}
+
+RazorKbIndicatorEventFilter::RazorKbIndicatorEventFilter(QObject *parent):
+ QObject(parent)
+{
+ if (!filterObject)
+ {
+ filterObject = this;
+
+ display = QX11Info::display();
+
+ if (initXkbExtension())
+ if (XkbSelectEvents(display, XkbUseCoreKbd, XkbIndicatorStateNotifyMask, XkbIndicatorStateNotifyMask))
+ oldEventFilter = QAbstractEventDispatcher::instance()->setEventFilter(::X11_eventFilter);
+ }
+}
+
+bool RazorKbIndicatorEventFilter::initXkbExtension(void)
+{
+ int code;
+ int major = XkbMajorVersion;
+ int minor = XkbMinorVersion;
+ int XkbErrorBase;
+
+ if (!XkbLibraryVersion(&major, &minor))
+ return false;
+ if (!XkbQueryExtension(display, &code, &XkbEventBase, &XkbErrorBase, &major, &minor))
+ return false;
+ if (!XkbUseExtension(display, &major, &minor))
+ return false;
+ return true;
+}
+
+bool RazorKbIndicatorEventFilter::X11_eventFilter(void *message)
+{
+ XkbEvent* event = static_cast<XkbEvent*>(message);
+
+ if (event->type == XkbEventBase + XkbEventCode)
+ if (event->any.xkb_type == XkbIndicatorStateNotify)
+ emit indicatorsChanged(event->indicators.changed, event->indicators.state);
+
+ if (oldEventFilter)
+ return oldEventFilter(message);
+
+ return false;
+}
+
+bool RazorKbIndicatorEventFilter::getLockStatus(int bit)
+{
+ bool state = false;
+ if (display)
+ {
+ unsigned n;
+ XkbGetIndicatorState(display, XkbUseCoreKbd, &n);
+ state = (n & (1 << bit));
+ }
+ return state;
+}
61 razorqt-panel/plugin-kbindicator/razorkbindicatoreventfilter.h
View
@@ -0,0 +1,61 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * Razor - a lightweight, Qt based, desktop toolset
+ * http://razor-qt.org
+ *
+ * Copyright: 2012 Razor team
+ * Authors:
+ * Kuzma Shapran <kuzma.shapran@gmail.com>
+ *
+ * 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 2.1 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 RAZORPANELKBINDICATOREVENTFILTER_H
+#define RAZORPANELKBINDICATOREVENTFILTER_H
+
+#include <QtCore/QAbstractEventDispatcher>
+
+#include <QtGui/QX11Info>
+
+
+class RazorKbIndicatorEventFilter : public QObject
+{
+ Q_OBJECT
+public:
+ RazorKbIndicatorEventFilter(QObject *parent = NULL);
+
+ bool getLockStatus(int bit);
+
+ static RazorKbIndicatorEventFilter* instance(void);
+
+signals:
+ void indicatorsChanged(unsigned int, unsigned int);
+
+private:
+ friend bool X11_eventFilter(void*);
+
+ Display *display;
+ int XkbEventBase;
+ QAbstractEventDispatcher::EventFilter oldEventFilter;
+
+ bool initXkbExtension(void);
+ bool X11_eventFilter(void *message);
+};
+
+
+#endif // RAZORPANELKBINDICATOREVENTFILTER_H
33 razorqt-resources/themes/a-mego/razor-panel.qss
View
@@ -184,3 +184,36 @@ MountButton:pressed {
#ShowDesktop > QToolButton:on {
background-color: transparent;
}
+
+
+/*
+ * KbIndicator
+ */
+#KbIndicator {
+ margin: 0px;
+ border: 0px;
+ padding: 0px;
+}
+
+#KbIndicator > QLabel {
+ margin-top: 4px;
+ margin-bottom: 4px;
+ margin-left: 0px;
+ margin-right: 0px;
+ border: 0px;
+ padding-top: 0px;
+ padding-bottom: 0px;
+ padding-left: 3px;
+ padding-right: 3px;
+}
+
+#KbIndicator > QLabel:enabled {
+ background: qradialgradient(cx:0.5, cy:0.5, radius: 0.5, fx:0.5, fy:0.5, stop:0 lightgray, stop:1 transparent);
+ color: black;
+}
+
+#KbIndicator > QLabel:disabled {
+ background: transparent;
+ color: gray;
+}
+
32 razorqt-resources/themes/ambiance/razor-panel.qss
View
@@ -196,3 +196,35 @@ MountButton:pressed {
margin: 2px;
border: 2px solid transparent;
}
+
+
+/*
+ * KbIndicator
+ */
+#KbIndicator {
+ margin: 0px;
+ border: 0px;
+ padding: 0px;
+}
+
+#KbIndicator > QLabel {
+ margin-top: 4px;
+ margin-bottom: 4px;
+ margin-left: 0px;
+ margin-right: 0px;
+ border: 0px;
+ padding-top: 0px;
+ padding-bottom: 0px;
+ padding-left: 3px;
+ padding-right: 3px;
+}
+
+#KbIndicator > QLabel:enabled {
+ background: qradialgradient(cx:0.5, cy:0.5, radius: 0.5, fx:0.5, fy:0.5, stop:0 coral, stop:1 transparent);
+ color: black;
+}
+
+#KbIndicator > QLabel:disabled {
+ background: transparent;
+ color: gray;
+}
32 razorqt-resources/themes/green/razor-panel.qss
View
@@ -157,3 +157,35 @@ MountButton {}
* ShowDesktop
*/
#ShowDesktop {}
+
+
+/*
+ * KbIndicator
+ */
+#KbIndicator {
+ margin: 0px;
+ border: 0px;
+ padding: 0px;
+}
+
+#KbIndicator > QLabel {
+ margin-top: 2px;
+ margin-bottom: 2px;
+ margin-left: 0px;
+ margin-right: 0px;
+ border: 0px;
+ padding-top: 0px;
+ padding-bottom: 0px;
+ padding-left: 3px;
+ padding-right: 3px;
+}
+
+#KbIndicator > QLabel:enabled {
+ background: qradialgradient(cx:0.5, cy:0.5, radius: 0.5, fx:0.5, fy:0.5, stop:0 lawngreen, stop:1 transparent);
+ color: black;
+}
+
+#KbIndicator > QLabel:disabled {
+ background: transparent;
+ color: gray;
+}
33 razorqt-resources/themes/light/razor-panel.qss
View
@@ -157,3 +157,36 @@ MountButton {}
* ShowDesktop
*/
#ShowDesktop {}
+
+
+/*
+ * KbIndicator
+ */
+#KbIndicator {
+ margin: 0px;
+ border: 0px;
+ padding: 0px;
+}
+
+#KbIndicator > QLabel {
+ margin-top: 2px;
+ margin-bottom: 2px;
+ margin-left: 0px;
+ margin-right: 0px;
+ border: 0px;
+ padding-top: 0px;
+ padding-bottom: 0px;
+ padding-left: 3px;
+ padding-right: 3px;
+}
+
+#KbIndicator > QLabel:enabled {
+ background: qradialgradient(cx:0.5, cy:0.5, radius: 0.5, fx:0.5, fy:0.5, stop:0 lightskyblue, stop:1 transparent);
+ color: black;
+}
+
+#KbIndicator > QLabel:disabled {
+ background: transparent;
+ color: gray;
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.