Browse Source

DesktopPicker: Add mouse wheel control

This lets us use scroll wheel up/down to move between columns and
shift + scroll wheel up/down to move between rows.
LuK1337 4 years ago
parent
commit
de09a92bf8
1 changed files with 19 additions and 0 deletions
  1. 19 0
      Userland/Applets/DesktopPicker/DesktopStatusWindow.cpp

+ 19 - 0
Userland/Applets/DesktopPicker/DesktopStatusWindow.cpp

@@ -67,6 +67,25 @@ public:
             GUI::WindowManagerServerConnection::the().async_set_virtual_desktop(row, col);
             GUI::WindowManagerServerConnection::the().async_set_virtual_desktop(row, col);
     }
     }
 
 
+    virtual void mousewheel_event(GUI::MouseEvent& event) override
+    {
+        auto& desktop = GUI::Desktop::the();
+
+        auto col = current_col();
+        auto row = current_row();
+
+        auto vcols = desktop.virtual_desktop_columns();
+        auto vrows = desktop.virtual_desktop_rows();
+        auto direction = event.wheel_delta() < 0 ? 1 : -1;
+
+        if (event.modifiers() & Mod_Shift)
+            col = abs((int)col + direction) % vcols;
+        else
+            row = abs((int)row + direction) % vrows;
+
+        GUI::WindowManagerServerConnection::the().async_set_virtual_desktop(row, col);
+    }
+
     unsigned current_row() const { return m_current_row; }
     unsigned current_row() const { return m_current_row; }
     void set_current_row(unsigned row) { m_current_row = row; }
     void set_current_row(unsigned row) { m_current_row = row; }
     unsigned current_col() const { return m_current_col; }
     unsigned current_col() const { return m_current_col; }