NetherSwap::NetherSwap(QWidget *parent) : QMainWindow(parent), settings_(this), is_dragging_(false), is_second_instance_(false), tray_icon_(QIcon(":/NetherSwap/Resources/icons/netherswap-tray.ico"), this) { qRegisterMetaType<GameStatus>("GameStatus"); qRegisterMetaType<HotkeySequence>("HotkeySequence"); QLocalSocket single_instance_checker; single_instance_checker.connectToServer("netherswap_instance_check"); if(single_instance_checker.waitForConnected(250)) { // connected means a server is running elsewhere, exit this one single_instance_checker.abort(); QTimer::singleShot(0, this, SLOT(close())); is_second_instance_ = true; return; } single_instance_checker.abort(); single_instance_server_ = new QLocalServer(this); // running a second instance should bring up the first connect(single_instance_server_, SIGNAL(newConnection()), this, SLOT(Unminimize())); single_instance_server_->listen("netherswap_instance_check"); QThread* monitor_thread = new QThread(); GameMonitor* monitor = new GameMonitor("DOTA 2", "Valve001"); monitor->moveToThread(monitor_thread); connect(monitor_thread, SIGNAL(started()), monitor, SLOT(Start())); connect(monitor_thread, SIGNAL(finished()), monitor, SLOT(deleteLater())); connect(monitor_thread, SIGNAL(finished()), monitor_thread, SLOT(deleteLater())); connect(this, SIGNAL(destroyed()), monitor_thread, SLOT(quit())); connect(monitor, SIGNAL(StatusChanged(GameStatus)), this, SLOT(StatusChanged(GameStatus))); ui.setupUi(this); ReadSettings(); connect(ui.in_game_hotkey_btn, SIGNAL(HotkeySet(const HotkeySequence&)), this, SLOT(InGameHotkeyChanged(const HotkeySequence&))); connect(ui.out_of_game_hotkey_btn, SIGNAL(HotkeySet(const HotkeySequence&)), this, SLOT(OutOfGameHotkeyChanged(const HotkeySequence&))); setWindowFlags(Qt::FramelessWindowHint); connect(ui.minimize_btn, SIGNAL(clicked()), this, SLOT(hide())); connect(ui.close_btn, SIGNAL(clicked()), this, SLOT(close())); tray_icon_.show(); connect(&tray_icon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(IconActivated(QSystemTrayIcon::ActivationReason))); ui.version_label->setText(QString("v%1.%2").arg(NETHERSWAP_VERSION_MAJOR) .arg(NETHERSWAP_VERSION_MINOR)); connect(monitor, SIGNAL(StatusMessage(const QString&)), ui.status_label, SLOT(setText(const QString&))); monitor_thread->start(); }
void NetherSwap::IconActivated(QSystemTrayIcon::ActivationReason reason) { switch(reason) { case QSystemTrayIcon::DoubleClick: { Unminimize(); break; } default: break; } }
void TestMap() { XSizeHints *hints; XWindowAttributes attr; Window w; /* Create the window. */ w = XCreateSimpleWindow(display, rootWindow, 100, 100, 200, 100, 0, 0, 0); XSelectInput(display, w, StructureNotifyMask | PropertyNotify); /* Map the window and wait for it. */ XMapWindow(display, w); Assert(AwaitEvent(MapNotify)); /* Unmap the window and wait for it. */ XUnmapWindow(display, w); Assert(AwaitEvent(UnmapNotify)); /* Map the window and wait for it (again). */ XMapWindow(display, w); Assert(AwaitEvent(MapNotify)); /* Minimize and wait. */ Minimize(w); Assert(AwaitEvent(UnmapNotify)); /* Restore and wait. */ Unminimize(w); Assert(AwaitEvent(MapNotify)); /* Maximize and wait. */ Maximize(w, 1, 1); Assert(AwaitEvent(ConfigureNotify)); /* Unmaximize and wait. */ Unmaximize(w, 0, 1); Assert(AwaitEvent(ConfigureNotify)); /* Unmaximize and wait. */ Unmaximize(w, 1, 0); Assert(AwaitEvent(ConfigureNotify)); /* Change the size hints. */ hints = XAllocSizeHints(); hints->flags = PMinSize; hints->min_width = 300; hints->min_height = 200; XSetWMNormalHints(display, w, hints); XFree(hints); XSync(display, False); sleep(1); IgnoreEvents(); XGetWindowAttributes(display, w, &attr); Assert(attr.width == 300); Assert(attr.height == 200); /* Shade and wait. */ Shade(w); Assert(AwaitEvent(UnmapNotify)); /* Maximize and wait. */ Maximize(w, 0, 1); Assert(AwaitEvent(MapNotify)); /* Shade and wait. */ Shade(w); Assert(AwaitEvent(UnmapNotify)); /* Unshade and wait. */ Unshade(w); Assert(AwaitEvent(MapNotify)); /* Destroy the window. */ XDestroyWindow(display, w); }