Skip to content

Commit

Permalink
Release 2.0 with new dropdown terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
vicr123 committed May 20, 2017
1 parent 0192ef6 commit d24f24f
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 22 deletions.
2 changes: 1 addition & 1 deletion about.ui
Expand Up @@ -45,7 +45,7 @@
</font>
</property>
<property name="text">
<string>theTerminal 1.0</string>
<string>theTerminal 2.0</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
Expand Down
19 changes: 15 additions & 4 deletions dropdown.cpp
@@ -1,6 +1,8 @@
#include "dropdown.h"
#include "ui_dropdown.h"

extern NativeEventFilter* filter;

Dropdown::Dropdown(QString workdir, QWidget *parent) :
QDialog(parent),
ui(new Ui::Dropdown)
Expand All @@ -9,13 +11,23 @@ Dropdown::Dropdown(QString workdir, QWidget *parent) :
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);

QMenu* menu = new QMenu();
menu->addAction(QIcon::fromTheme("application-exit"), "Exit", [=]() {
menu->addAction(QIcon::fromTheme("configure"), "Settings", [=] {
KeyCode kc = XKeysymToKeycode(QX11Info::display(), settings.value("dropdown/key", XK_F12).toLongLong());
XUngrabKey(QX11Info::display(), kc, AnyModifier, DefaultRootWindow(QX11Info::display()));

SettingsWindow* settingsWin = new SettingsWindow();
settingsWin->exec();
settingsWin->deleteLater();

kc = XKeysymToKeycode(QX11Info::display(), settings.value("dropdown/key", XK_F12).toLongLong());
XGrabKey(QX11Info::display(), kc, AnyModifier, DefaultRootWindow(QX11Info::display()), true, GrabModeAsync, GrabModeAsync);
});
menu->addAction(QIcon::fromTheme("application-exit"), "Exit", [=] {
this->close();
});
ui->menuButton->setPopupMode(QToolButton::InstantPopup);
ui->menuButton->setMenu(menu);

NativeEventFilter* filter = new NativeEventFilter;
connect(filter, &NativeEventFilter::toggleTerminal, [=]() {
if (this->isVisible()) {
this->hide();
Expand All @@ -24,9 +36,8 @@ Dropdown::Dropdown(QString workdir, QWidget *parent) :
}
});

KeyCode keycode = XKeysymToKeycode(QX11Info::display(), XF86XK_LaunchB);
KeyCode keycode = XKeysymToKeycode(QX11Info::display(), settings.value("dropdown/key", XK_F12).toLongLong());
XGrabKey(QX11Info::display(), keycode, AnyModifier, DefaultRootWindow(QX11Info::display()), true, GrabModeAsync, GrabModeAsync);
QApplication::instance()->installNativeEventFilter(filter);

newTab(workdir);
}
Expand Down
5 changes: 2 additions & 3 deletions dropdown.h
Expand Up @@ -17,9 +17,7 @@
#include "terminalwidget.h"
#include <ttoast.h>
#include <tpropertyanimation.h>
#include <X11/Xlib.h>
#include <X11/XF86keysym.h>
#include <X11/Xatom.h>
#include "settingswindow.h"

namespace Ui {
class Dropdown;
Expand Down Expand Up @@ -58,6 +56,7 @@ private slots:
QMap<terminalWidget*, QPushButton*> terminalButtons;
bool isExpanded = false;
QScreen* currentScreen = NULL;
QSettings settings;

void paintEvent(QPaintEvent* event);
};
Expand Down
9 changes: 9 additions & 0 deletions main.cpp
Expand Up @@ -2,10 +2,16 @@
#include "dropdown.h"
#include <QApplication>

NativeEventFilter* filter;

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

a.setOrganizationName("theSuite");
a.setOrganizationDomain("");
a.setApplicationName("theTerminal");

QString workDir;
bool dropdown = false;

Expand All @@ -26,6 +32,9 @@ int main(int argc, char *argv[])
}
}

filter = new NativeEventFilter;
a.installNativeEventFilter(filter);

if (dropdown) {
Dropdown* w = new Dropdown(workDir);
} else {
Expand Down
7 changes: 7 additions & 0 deletions mainwindow.cpp
Expand Up @@ -149,3 +149,10 @@ void MainWindow::on_actionAbout_triggered()
About* window = new About(this);
window->exec();
}

void MainWindow::on_actionSettings_triggered()
{
SettingsWindow* settings = new SettingsWindow();
settings->exec();
settings->deleteLater();
}
3 changes: 3 additions & 0 deletions mainwindow.h
Expand Up @@ -5,6 +5,7 @@
#include <QPushButton>
#include "terminalwidget.h"
#include "about.h"
#include "settingswindow.h"

namespace Ui {
class MainWindow;
Expand Down Expand Up @@ -43,6 +44,8 @@ private slots:

void on_actionAbout_triggered();

void on_actionSettings_triggered();

private:
Ui::MainWindow *ui;

Expand Down
32 changes: 23 additions & 9 deletions mainwindow.ui
Expand Up @@ -79,7 +79,7 @@
<x>0</x>
<y>0</y>
<width>570</width>
<height>23</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
Expand All @@ -89,6 +89,8 @@
<addaction name="actionNew_Window"/>
<addaction name="actionNew_Tab"/>
<addaction name="separator"/>
<addaction name="actionSettings"/>
<addaction name="separator"/>
<addaction name="actionClose_Tab"/>
<addaction name="actionExit"/>
</widget>
Expand Down Expand Up @@ -177,40 +179,52 @@
</action>
<action name="actionClose_Tab">
<property name="icon">
<iconset theme="tab-close"/>
<iconset theme="tab-close">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Close Tab</string>
<string>&amp;Close Tab</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+W</string>
</property>
</action>
<action name="actionFind">
<property name="icon">
<iconset theme="edit-find"/>
<iconset theme="edit-find">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Find...</string>
<string>&amp;Find...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+F</string>
</property>
</action>
<action name="actionGo_Full_Screen">
<property name="icon">
<iconset theme="view-fullscreen"/>
<iconset theme="view-fullscreen">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Go Full Screen</string>
<string>&amp;Go Full Screen</string>
</property>
</action>
<action name="actionAbout">
<property name="icon">
<iconset theme="help-about"/>
<iconset theme="help-about">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;About</string>
</property>
</action>
<action name="actionSettings">
<property name="icon">
<iconset theme="configure"/>
</property>
<property name="text">
<string>About</string>
<string>Settings</string>
</property>
</action>
</widget>
Expand Down
20 changes: 18 additions & 2 deletions nativeeventfilter.cpp
Expand Up @@ -11,10 +11,26 @@ bool NativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *mes
if (event->response_type == XCB_KEY_RELEASE) {
xcb_key_release_event_t* button = static_cast<xcb_key_release_event_t*>(message);

if (button->detail == XKeysymToKeycode(QX11Info::display(), XF86XK_LaunchB)) {
emit toggleTerminal();
if (capturingKeyPress) {
KeySym keyPressed = XkbKeycodeToKeysym(QX11Info::display(), button->detail, 0, button->state & ShiftMask ? 1 : 0);

settings.setValue("dropdown/key", QVariant::fromValue(keyPressed));
settings.setValue("dropdown/keyState", button->state);
settings.setValue("dropdown/keyString", XKeysymToString(keyPressed));
captureKeyPresses(false);
emit keypressCaptureComplete();
return true;
} else {
if (button->detail == XKeysymToKeycode(QX11Info::display(), settings.value("dropdown/key", XK_F12).toLongLong())) {
emit toggleTerminal();
return true;
}
}
}
}
return false;
}

void NativeEventFilter::captureKeyPresses(bool capture) {
capturingKeyPress = capture;
}
8 changes: 8 additions & 0 deletions nativeeventfilter.h
Expand Up @@ -4,14 +4,17 @@
#include <QObject>
#include <QAbstractNativeEventFilter>
#include <QX11Info>
#include <QSettings>
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>
#include <X11/XF86keysym.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>

#undef None
#undef Status
#undef Bool

class NativeEventFilter : public QObject, public QAbstractNativeEventFilter
{
Expand All @@ -21,11 +24,16 @@ class NativeEventFilter : public QObject, public QAbstractNativeEventFilter

signals:
void toggleTerminal();
void keypressCaptureComplete();

public slots:
void captureKeyPresses(bool capture);

private:
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);

bool capturingKeyPress = false;
QSettings settings;
};

#endif // NATIVEEVENTFILTER_H
55 changes: 55 additions & 0 deletions settingswindow.cpp
@@ -0,0 +1,55 @@
#include "settingswindow.h"
#include "ui_settingswindow.h"

extern bool capturingKeyPress;
extern NativeEventFilter* filter;

SettingsWindow::SettingsWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::SettingsWindow)
{
ui->setupUi(this);

ui->settingsLists->addItem(new QListWidgetItem(QIcon::fromTheme("configure"), "General"));
ui->settingsLists->addItem(new QListWidgetItem(QIcon::fromTheme("go-down"), "Drop Down"));

on_keybindingButton_toggled(false);

connect(filter, SIGNAL(keypressCaptureComplete()), this, SLOT(keypressCaptureComplete()));
}

SettingsWindow::~SettingsWindow()
{
disconnect(filter, SIGNAL(keypressCaptureComplete()), this, SLOT(keypressCaptureComplete()));
delete ui;
}

void SettingsWindow::on_settingsLists_currentRowChanged(int currentRow)
{
ui->pages->setCurrentIndex(currentRow);
}

void SettingsWindow::on_DoneButton_clicked()
{
this->close();
}

void SettingsWindow::on_keybindingButton_toggled(bool checked)
{
if (checked) {
//Capture keyboard
XGrabKeyboard(QX11Info::display(), RootWindow(QX11Info::display(), 0), True, GrabModeAsync, GrabModeAsync, CurrentTime);
filter->captureKeyPresses(true);

ui->keybindingButton->setText("Strike a key!");
} else {
XUngrabKeyboard(QX11Info::display(), CurrentTime);
filter->captureKeyPresses(false);

ui->keybindingButton->setText(settings.value("dropdown/keyString", "F12").toString());
}
}

void SettingsWindow::keypressCaptureComplete() {
ui->keybindingButton->setChecked(false);
}
51 changes: 51 additions & 0 deletions settingswindow.h
@@ -0,0 +1,51 @@
#ifndef SETTINGSWINDOW_H
#define SETTINGSWINDOW_H

#include <QDialog>
#include <QStackedWidget>
#include <QListWidget>
#include <QKeySequenceEdit>
#include <QX11Info>
#include "nativeeventfilter.h"
#include <X11/Xlib.h>
#include <X11/XF86keysym.h>
#include <X11/Xatom.h>

#undef Unsorted
#undef None
#undef KeyPress
#undef KeyRelease
#undef FocusIn
#undef FocusOut
#undef FontChange
#undef Expose
#undef Bool

namespace Ui {
class SettingsWindow;
}

class SettingsWindow : public QDialog
{
Q_OBJECT

public:
explicit SettingsWindow(QWidget *parent = 0);
~SettingsWindow();

private slots:
void on_settingsLists_currentRowChanged(int currentRow);

void on_DoneButton_clicked();

void on_keybindingButton_toggled(bool checked);

void keypressCaptureComplete();

private:
Ui::SettingsWindow *ui;

QSettings settings;
};

#endif // SETTINGSWINDOW_H

0 comments on commit d24f24f

Please sign in to comment.