Changeset View
Changeset View
Standalone View
Standalone View
input.cpp
Show All 30 Lines | |||||
31 | #include "main.h" | 31 | #include "main.h" | ||
32 | #ifdef KWIN_BUILD_TABBOX | 32 | #ifdef KWIN_BUILD_TABBOX | ||
33 | #include "tabbox/tabbox.h" | 33 | #include "tabbox/tabbox.h" | ||
34 | #endif | 34 | #endif | ||
35 | #include "unmanaged.h" | 35 | #include "unmanaged.h" | ||
36 | #include "screenedge.h" | 36 | #include "screenedge.h" | ||
37 | #include "screens.h" | 37 | #include "screens.h" | ||
38 | #include "workspace.h" | 38 | #include "workspace.h" | ||
39 | #if HAVE_INPUT | | |||
40 | #include "libinput/connection.h" | 39 | #include "libinput/connection.h" | ||
41 | #include "libinput/device.h" | 40 | #include "libinput/device.h" | ||
42 | #endif | | |||
43 | #include "platform.h" | 41 | #include "platform.h" | ||
44 | #include "popup_input_filter.h" | 42 | #include "popup_input_filter.h" | ||
45 | #include "shell_client.h" | 43 | #include "shell_client.h" | ||
46 | #include "wayland_server.h" | 44 | #include "wayland_server.h" | ||
47 | #include <KWayland/Server/display.h> | 45 | #include <KWayland/Server/display.h> | ||
48 | #include <KWayland/Server/fakeinput_interface.h> | 46 | #include <KWayland/Server/fakeinput_interface.h> | ||
49 | #include <KWayland/Server/seat_interface.h> | 47 | #include <KWayland/Server/seat_interface.h> | ||
50 | #include <KWayland/Server/relativepointer_interface.h> | 48 | #include <KWayland/Server/relativepointer_interface.h> | ||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | 175 | { | |||
186 | case QEvent::KeyRelease: | 184 | case QEvent::KeyRelease: | ||
187 | waylandServer()->seat()->keyReleased(event->nativeScanCode()); | 185 | waylandServer()->seat()->keyReleased(event->nativeScanCode()); | ||
188 | break; | 186 | break; | ||
189 | default: | 187 | default: | ||
190 | break; | 188 | break; | ||
191 | } | 189 | } | ||
192 | } | 190 | } | ||
193 | 191 | | |||
194 | #if HAVE_INPUT | | |||
195 | class VirtualTerminalFilter : public InputEventFilter { | 192 | class VirtualTerminalFilter : public InputEventFilter { | ||
196 | public: | 193 | public: | ||
197 | bool keyEvent(QKeyEvent *event) override { | 194 | bool keyEvent(QKeyEvent *event) override { | ||
198 | // really on press and not on release? X11 switches on press. | 195 | // really on press and not on release? X11 switches on press. | ||
199 | if (event->type() == QEvent::KeyPress && !event->isAutoRepeat()) { | 196 | if (event->type() == QEvent::KeyPress && !event->isAutoRepeat()) { | ||
200 | const xkb_keysym_t keysym = event->nativeVirtualKey(); | 197 | const xkb_keysym_t keysym = event->nativeVirtualKey(); | ||
201 | if (keysym >= XKB_KEY_XF86Switch_VT_1 && keysym <= XKB_KEY_XF86Switch_VT_12) { | 198 | if (keysym >= XKB_KEY_XF86Switch_VT_1 && keysym <= XKB_KEY_XF86Switch_VT_12) { | ||
202 | LogindIntegration::self()->switchVirtualTerminal(keysym - XKB_KEY_XF86Switch_VT_1 + 1); | 199 | LogindIntegration::self()->switchVirtualTerminal(keysym - XKB_KEY_XF86Switch_VT_1 + 1); | ||
203 | return true; | 200 | return true; | ||
204 | } | 201 | } | ||
205 | } | 202 | } | ||
206 | return false; | 203 | return false; | ||
207 | } | 204 | } | ||
208 | }; | 205 | }; | ||
209 | #endif | | |||
210 | 206 | | |||
211 | class TerminateServerFilter : public InputEventFilter { | 207 | class TerminateServerFilter : public InputEventFilter { | ||
212 | public: | 208 | public: | ||
213 | bool keyEvent(QKeyEvent *event) override { | 209 | bool keyEvent(QKeyEvent *event) override { | ||
214 | if (event->type() == QEvent::KeyPress && !event->isAutoRepeat()) { | 210 | if (event->type() == QEvent::KeyPress && !event->isAutoRepeat()) { | ||
215 | if (event->nativeVirtualKey() == XKB_KEY_Terminate_Server) { | 211 | if (event->nativeVirtualKey() == XKB_KEY_Terminate_Server) { | ||
216 | qCWarning(KWIN_CORE) << "Request to terminate server"; | 212 | qCWarning(KWIN_CORE) << "Request to terminate server"; | ||
217 | QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection); | 213 | QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection); | ||
▲ Show 20 Lines • Show All 1282 Lines • ▼ Show 20 Line(s) | 1494 | InputRedirection::InputRedirection(QObject *parent) | |||
1500 | , m_keyboard(new KeyboardInputRedirection(this)) | 1496 | , m_keyboard(new KeyboardInputRedirection(this)) | ||
1501 | , m_pointer(new PointerInputRedirection(this)) | 1497 | , m_pointer(new PointerInputRedirection(this)) | ||
1502 | , m_touch(new TouchInputRedirection(this)) | 1498 | , m_touch(new TouchInputRedirection(this)) | ||
1503 | , m_shortcuts(new GlobalShortcutsManager(this)) | 1499 | , m_shortcuts(new GlobalShortcutsManager(this)) | ||
1504 | { | 1500 | { | ||
1505 | qRegisterMetaType<KWin::InputRedirection::KeyboardKeyState>(); | 1501 | qRegisterMetaType<KWin::InputRedirection::KeyboardKeyState>(); | ||
1506 | qRegisterMetaType<KWin::InputRedirection::PointerButtonState>(); | 1502 | qRegisterMetaType<KWin::InputRedirection::PointerButtonState>(); | ||
1507 | qRegisterMetaType<KWin::InputRedirection::PointerAxis>(); | 1503 | qRegisterMetaType<KWin::InputRedirection::PointerAxis>(); | ||
1508 | #if HAVE_INPUT | | |||
1509 | if (Application::usesLibinput()) { | 1504 | if (Application::usesLibinput()) { | ||
1510 | if (LogindIntegration::self()->hasSessionControl()) { | 1505 | if (LogindIntegration::self()->hasSessionControl()) { | ||
1511 | setupLibInput(); | 1506 | setupLibInput(); | ||
1512 | } else { | 1507 | } else { | ||
1513 | LibInput::Connection::createThread(); | 1508 | LibInput::Connection::createThread(); | ||
1514 | if (LogindIntegration::self()->isConnected()) { | 1509 | if (LogindIntegration::self()->isConnected()) { | ||
1515 | LogindIntegration::self()->takeControl(); | 1510 | LogindIntegration::self()->takeControl(); | ||
1516 | } else { | 1511 | } else { | ||
1517 | connect(LogindIntegration::self(), &LogindIntegration::connectedChanged, LogindIntegration::self(), &LogindIntegration::takeControl); | 1512 | connect(LogindIntegration::self(), &LogindIntegration::connectedChanged, LogindIntegration::self(), &LogindIntegration::takeControl); | ||
1518 | } | 1513 | } | ||
1519 | connect(LogindIntegration::self(), &LogindIntegration::hasSessionControlChanged, this, | 1514 | connect(LogindIntegration::self(), &LogindIntegration::hasSessionControlChanged, this, | ||
1520 | [this] (bool sessionControl) { | 1515 | [this] (bool sessionControl) { | ||
1521 | if (sessionControl) { | 1516 | if (sessionControl) { | ||
1522 | setupLibInput(); | 1517 | setupLibInput(); | ||
1523 | } | 1518 | } | ||
1524 | } | 1519 | } | ||
1525 | ); | 1520 | ); | ||
1526 | } | 1521 | } | ||
1527 | } | 1522 | } | ||
1528 | #endif | | |||
1529 | connect(kwinApp(), &Application::workspaceCreated, this, &InputRedirection::setupWorkspace); | 1523 | connect(kwinApp(), &Application::workspaceCreated, this, &InputRedirection::setupWorkspace); | ||
1530 | reconfigure(); | 1524 | reconfigure(); | ||
1531 | } | 1525 | } | ||
1532 | 1526 | | |||
1533 | InputRedirection::~InputRedirection() | 1527 | InputRedirection::~InputRedirection() | ||
1534 | { | 1528 | { | ||
1535 | s_self = NULL; | 1529 | s_self = NULL; | ||
1536 | qDeleteAll(m_filters); | 1530 | qDeleteAll(m_filters); | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 1568 | if (waylandServer()) { | |||
1665 | m_pointer->init(); | 1659 | m_pointer->init(); | ||
1666 | m_touch->init(); | 1660 | m_touch->init(); | ||
1667 | } | 1661 | } | ||
1668 | setupInputFilters(); | 1662 | setupInputFilters(); | ||
1669 | } | 1663 | } | ||
1670 | 1664 | | |||
1671 | void InputRedirection::setupInputFilters() | 1665 | void InputRedirection::setupInputFilters() | ||
1672 | { | 1666 | { | ||
1673 | #if HAVE_INPUT | | |||
1674 | if (LogindIntegration::self()->hasSessionControl()) { | 1667 | if (LogindIntegration::self()->hasSessionControl()) { | ||
1675 | installInputEventFilter(new VirtualTerminalFilter); | 1668 | installInputEventFilter(new VirtualTerminalFilter); | ||
1676 | } | 1669 | } | ||
1677 | #endif | | |||
1678 | if (waylandServer()) { | 1670 | if (waylandServer()) { | ||
1679 | installInputEventFilter(new TerminateServerFilter); | 1671 | installInputEventFilter(new TerminateServerFilter); | ||
1680 | installInputEventFilter(new DragAndDropInputFilter); | 1672 | installInputEventFilter(new DragAndDropInputFilter); | ||
1681 | installInputEventFilter(new LockScreenFilter); | 1673 | installInputEventFilter(new LockScreenFilter); | ||
1682 | installInputEventFilter(new PopupInputFilter); | 1674 | installInputEventFilter(new PopupInputFilter); | ||
1683 | m_pointerConstraintsFilter = new PointerConstraintsFilter; | 1675 | m_pointerConstraintsFilter = new PointerConstraintsFilter; | ||
1684 | installInputEventFilter(m_pointerConstraintsFilter); | 1676 | installInputEventFilter(m_pointerConstraintsFilter); | ||
1685 | m_windowSelector = new WindowSelectorFilter; | 1677 | m_windowSelector = new WindowSelectorFilter; | ||
Show All 11 Lines | 1685 | #endif | |||
1697 | if (waylandServer()) { | 1689 | if (waylandServer()) { | ||
1698 | installInputEventFilter(new WindowActionInputFilter); | 1690 | installInputEventFilter(new WindowActionInputFilter); | ||
1699 | installInputEventFilter(new ForwardInputFilter); | 1691 | installInputEventFilter(new ForwardInputFilter); | ||
1700 | } | 1692 | } | ||
1701 | } | 1693 | } | ||
1702 | 1694 | | |||
1703 | void InputRedirection::reconfigure() | 1695 | void InputRedirection::reconfigure() | ||
1704 | { | 1696 | { | ||
1705 | #if HAVE_INPUT | | |||
1706 | if (Application::usesLibinput()) { | 1697 | if (Application::usesLibinput()) { | ||
1707 | auto inputConfig = kwinApp()->inputConfig(); | 1698 | auto inputConfig = kwinApp()->inputConfig(); | ||
1708 | inputConfig->reparseConfiguration(); | 1699 | inputConfig->reparseConfiguration(); | ||
1709 | const auto config = inputConfig->group(QStringLiteral("keyboard")); | 1700 | const auto config = inputConfig->group(QStringLiteral("keyboard")); | ||
1710 | const int delay = config.readEntry("RepeatDelay", 660); | 1701 | const int delay = config.readEntry("RepeatDelay", 660); | ||
1711 | const int rate = config.readEntry("RepeatRate", 25); | 1702 | const int rate = config.readEntry("RepeatRate", 25); | ||
1712 | const bool enabled = config.readEntry("KeyboardRepeating", 0) == 0; | 1703 | const bool enabled = config.readEntry("KeyboardRepeating", 0) == 0; | ||
1713 | 1704 | | |||
1714 | waylandServer()->seat()->setKeyRepeatInfo(enabled ? rate : 0, delay); | 1705 | waylandServer()->seat()->setKeyRepeatInfo(enabled ? rate : 0, delay); | ||
1715 | } | 1706 | } | ||
1716 | #endif | | |||
1717 | } | 1707 | } | ||
1718 | 1708 | | |||
1719 | static KWayland::Server::SeatInterface *findSeat() | 1709 | static KWayland::Server::SeatInterface *findSeat() | ||
1720 | { | 1710 | { | ||
1721 | auto server = waylandServer(); | 1711 | auto server = waylandServer(); | ||
1722 | if (!server) { | 1712 | if (!server) { | ||
1723 | return nullptr; | 1713 | return nullptr; | ||
1724 | } | 1714 | } | ||
1725 | return server->seat(); | 1715 | return server->seat(); | ||
1726 | } | 1716 | } | ||
1727 | 1717 | | |||
1728 | void InputRedirection::setupLibInput() | 1718 | void InputRedirection::setupLibInput() | ||
1729 | { | 1719 | { | ||
1730 | #if HAVE_INPUT | | |||
1731 | if (!Application::usesLibinput()) { | 1720 | if (!Application::usesLibinput()) { | ||
1732 | return; | 1721 | return; | ||
1733 | } | 1722 | } | ||
1734 | if (m_libInput) { | 1723 | if (m_libInput) { | ||
1735 | return; | 1724 | return; | ||
1736 | } | 1725 | } | ||
1737 | LibInput::Connection *conn = LibInput::Connection::create(this); | 1726 | LibInput::Connection *conn = LibInput::Connection::create(this); | ||
1738 | m_libInput = conn; | 1727 | m_libInput = conn; | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 1824 | connect(LogindIntegration::self(), &LogindIntegration::sessionActiveChanged, m_libInput, | |||
1836 | [this] (bool active) { | 1825 | [this] (bool active) { | ||
1837 | if (!active) { | 1826 | if (!active) { | ||
1838 | m_libInput->deactivate(); | 1827 | m_libInput->deactivate(); | ||
1839 | } | 1828 | } | ||
1840 | } | 1829 | } | ||
1841 | ); | 1830 | ); | ||
1842 | } | 1831 | } | ||
1843 | setupTouchpadShortcuts(); | 1832 | setupTouchpadShortcuts(); | ||
1844 | #endif | | |||
1845 | } | 1833 | } | ||
1846 | 1834 | | |||
1847 | void InputRedirection::setupTouchpadShortcuts() | 1835 | void InputRedirection::setupTouchpadShortcuts() | ||
1848 | { | 1836 | { | ||
1849 | if (!m_libInput) { | 1837 | if (!m_libInput) { | ||
1850 | return; | 1838 | return; | ||
1851 | } | 1839 | } | ||
1852 | #if HAVE_INPUT | | |||
1853 | QAction *touchpadToggleAction = new QAction(this); | 1840 | QAction *touchpadToggleAction = new QAction(this); | ||
1854 | QAction *touchpadOnAction = new QAction(this); | 1841 | QAction *touchpadOnAction = new QAction(this); | ||
1855 | QAction *touchpadOffAction = new QAction(this); | 1842 | QAction *touchpadOffAction = new QAction(this); | ||
1856 | 1843 | | |||
1857 | touchpadToggleAction->setObjectName(QStringLiteral("Toggle Touchpad")); | 1844 | touchpadToggleAction->setObjectName(QStringLiteral("Toggle Touchpad")); | ||
1858 | touchpadToggleAction->setProperty("componentName", s_touchpadComponent); | 1845 | touchpadToggleAction->setProperty("componentName", s_touchpadComponent); | ||
1859 | touchpadOnAction->setObjectName(QStringLiteral("Enable Touchpad")); | 1846 | touchpadOnAction->setObjectName(QStringLiteral("Enable Touchpad")); | ||
1860 | touchpadOnAction->setProperty("componentName", s_touchpadComponent); | 1847 | touchpadOnAction->setProperty("componentName", s_touchpadComponent); | ||
1861 | touchpadOffAction->setObjectName(QStringLiteral("Disable Touchpad")); | 1848 | touchpadOffAction->setObjectName(QStringLiteral("Disable Touchpad")); | ||
1862 | touchpadOffAction->setProperty("componentName", s_touchpadComponent); | 1849 | touchpadOffAction->setProperty("componentName", s_touchpadComponent); | ||
1863 | KGlobalAccel::self()->setDefaultShortcut(touchpadToggleAction, QList<QKeySequence>{Qt::Key_TouchpadToggle}); | 1850 | KGlobalAccel::self()->setDefaultShortcut(touchpadToggleAction, QList<QKeySequence>{Qt::Key_TouchpadToggle}); | ||
1864 | KGlobalAccel::self()->setShortcut(touchpadToggleAction, QList<QKeySequence>{Qt::Key_TouchpadToggle}); | 1851 | KGlobalAccel::self()->setShortcut(touchpadToggleAction, QList<QKeySequence>{Qt::Key_TouchpadToggle}); | ||
1865 | KGlobalAccel::self()->setDefaultShortcut(touchpadOnAction, QList<QKeySequence>{Qt::Key_TouchpadOn}); | 1852 | KGlobalAccel::self()->setDefaultShortcut(touchpadOnAction, QList<QKeySequence>{Qt::Key_TouchpadOn}); | ||
1866 | KGlobalAccel::self()->setShortcut(touchpadOnAction, QList<QKeySequence>{Qt::Key_TouchpadOn}); | 1853 | KGlobalAccel::self()->setShortcut(touchpadOnAction, QList<QKeySequence>{Qt::Key_TouchpadOn}); | ||
1867 | KGlobalAccel::self()->setDefaultShortcut(touchpadOffAction, QList<QKeySequence>{Qt::Key_TouchpadOff}); | 1854 | KGlobalAccel::self()->setDefaultShortcut(touchpadOffAction, QList<QKeySequence>{Qt::Key_TouchpadOff}); | ||
1868 | KGlobalAccel::self()->setShortcut(touchpadOffAction, QList<QKeySequence>{Qt::Key_TouchpadOff}); | 1855 | KGlobalAccel::self()->setShortcut(touchpadOffAction, QList<QKeySequence>{Qt::Key_TouchpadOff}); | ||
1869 | #ifndef KWIN_BUILD_TESTING | 1856 | #ifndef KWIN_BUILD_TESTING | ||
1870 | registerShortcut(Qt::Key_TouchpadToggle, touchpadToggleAction); | 1857 | registerShortcut(Qt::Key_TouchpadToggle, touchpadToggleAction); | ||
1871 | registerShortcut(Qt::Key_TouchpadOn, touchpadOnAction); | 1858 | registerShortcut(Qt::Key_TouchpadOn, touchpadOnAction); | ||
1872 | registerShortcut(Qt::Key_TouchpadOff, touchpadOffAction); | 1859 | registerShortcut(Qt::Key_TouchpadOff, touchpadOffAction); | ||
1873 | #endif | 1860 | #endif | ||
1874 | connect(touchpadToggleAction, &QAction::triggered, m_libInput, &LibInput::Connection::toggleTouchpads); | 1861 | connect(touchpadToggleAction, &QAction::triggered, m_libInput, &LibInput::Connection::toggleTouchpads); | ||
1875 | connect(touchpadOnAction, &QAction::triggered, m_libInput, &LibInput::Connection::enableTouchpads); | 1862 | connect(touchpadOnAction, &QAction::triggered, m_libInput, &LibInput::Connection::enableTouchpads); | ||
1876 | connect(touchpadOffAction, &QAction::triggered, m_libInput, &LibInput::Connection::disableTouchpads); | 1863 | connect(touchpadOffAction, &QAction::triggered, m_libInput, &LibInput::Connection::disableTouchpads); | ||
1877 | #endif | | |||
1878 | } | 1864 | } | ||
1879 | 1865 | | |||
1880 | bool InputRedirection::hasAlphaNumericKeyboard() | 1866 | bool InputRedirection::hasAlphaNumericKeyboard() | ||
1881 | { | 1867 | { | ||
1882 | #if HAVE_INPUT | | |||
1883 | if (m_libInput) { | 1868 | if (m_libInput) { | ||
1884 | return m_libInput->hasAlphaNumericKeyboard(); | 1869 | return m_libInput->hasAlphaNumericKeyboard(); | ||
1885 | } | 1870 | } | ||
1886 | #endif | | |||
1887 | return true; | 1871 | return true; | ||
1888 | } | 1872 | } | ||
1889 | 1873 | | |||
1890 | bool InputRedirection::hasTabletModeSwitch() | 1874 | bool InputRedirection::hasTabletModeSwitch() | ||
1891 | { | 1875 | { | ||
1892 | #if HAVE_INPUT | 1876 | #if HAVE_INPUT | ||
1893 | if (m_libInput) { | 1877 | if (m_libInput) { | ||
1894 | return m_libInput->hasTabletModeSwitch(); | 1878 | return m_libInput->hasTabletModeSwitch(); | ||
1895 | } | 1879 | } | ||
1896 | #endif | 1880 | #endif | ||
1897 | return false; | 1881 | return false; | ||
1898 | } | 1882 | } | ||
1899 | 1883 | | |||
1900 | void InputRedirection::setupLibInputWithScreens() | 1884 | void InputRedirection::setupLibInputWithScreens() | ||
1901 | { | 1885 | { | ||
1902 | #if HAVE_INPUT | | |||
1903 | if (!screens() || !m_libInput) { | 1886 | if (!screens() || !m_libInput) { | ||
1904 | return; | 1887 | return; | ||
1905 | } | 1888 | } | ||
1906 | m_libInput->setScreenSize(screens()->size()); | 1889 | m_libInput->setScreenSize(screens()->size()); | ||
1907 | m_libInput->updateScreens(); | 1890 | m_libInput->updateScreens(); | ||
1908 | connect(screens(), &Screens::sizeChanged, this, | 1891 | connect(screens(), &Screens::sizeChanged, this, | ||
1909 | [this] { | 1892 | [this] { | ||
1910 | m_libInput->setScreenSize(screens()->size()); | 1893 | m_libInput->setScreenSize(screens()->size()); | ||
1911 | } | 1894 | } | ||
1912 | ); | 1895 | ); | ||
1913 | connect(screens(), &Screens::changed, m_libInput, &LibInput::Connection::updateScreens); | 1896 | connect(screens(), &Screens::changed, m_libInput, &LibInput::Connection::updateScreens); | ||
1914 | #endif | | |||
1915 | } | 1897 | } | ||
1916 | 1898 | | |||
1917 | void InputRedirection::processPointerMotion(const QPointF &pos, uint32_t time) | 1899 | void InputRedirection::processPointerMotion(const QPointF &pos, uint32_t time) | ||
1918 | { | 1900 | { | ||
1919 | m_pointer->processMotion(pos, time); | 1901 | m_pointer->processMotion(pos, time); | ||
1920 | } | 1902 | } | ||
1921 | 1903 | | |||
1922 | void InputRedirection::processPointerButton(uint32_t button, InputRedirection::PointerButtonState state, uint32_t time) | 1904 | void InputRedirection::processPointerButton(uint32_t button, InputRedirection::PointerButtonState state, uint32_t time) | ||
▲ Show 20 Lines • Show All 309 Lines • Show Last 20 Lines |