mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
WindowServer: Allow clicking on windows in the window switcher
You can now switch between windows using your mouse to click them in the window switcher. :^)
This commit is contained in:
parent
2ba06662b6
commit
ba135dc0c0
2 changed files with 56 additions and 18 deletions
|
@ -71,6 +71,24 @@ Window* WindowSwitcher::selected_window()
|
||||||
return m_windows[m_selected_index].ptr();
|
return m_windows[m_selected_index].ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowSwitcher::event(Core::Event& event)
|
||||||
|
{
|
||||||
|
if (!static_cast<Event&>(event).is_mouse_event())
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto& mouse_event = static_cast<MouseEvent&>(event);
|
||||||
|
if (mouse_event.type() == Event::MouseDown) {
|
||||||
|
for (int i = 0; i < m_windows.size(); ++i) {
|
||||||
|
auto item_rect = this->item_rect(i);
|
||||||
|
if (item_rect.contains(mouse_event.position())) {
|
||||||
|
select_window_at_index(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event.accept();
|
||||||
|
}
|
||||||
|
|
||||||
void WindowSwitcher::on_key_event(const KeyEvent& event)
|
void WindowSwitcher::on_key_event(const KeyEvent& event)
|
||||||
{
|
{
|
||||||
if (event.type() == Event::KeyUp) {
|
if (event.type() == Event::KeyUp) {
|
||||||
|
@ -94,21 +112,40 @@ void WindowSwitcher::on_key_event(const KeyEvent& event)
|
||||||
}
|
}
|
||||||
ASSERT(!m_windows.is_empty());
|
ASSERT(!m_windows.is_empty());
|
||||||
|
|
||||||
|
int new_selected_index;
|
||||||
|
|
||||||
if (!event.shift()) {
|
if (!event.shift()) {
|
||||||
m_selected_index = (m_selected_index + 1) % m_windows.size();
|
new_selected_index = (m_selected_index + 1) % m_windows.size();
|
||||||
} else {
|
} else {
|
||||||
m_selected_index = (m_selected_index - 1) % m_windows.size();
|
new_selected_index = (m_selected_index - 1) % m_windows.size();
|
||||||
if (m_selected_index < 0)
|
if (new_selected_index < 0)
|
||||||
m_selected_index = m_windows.size() - 1;
|
new_selected_index = m_windows.size() - 1;
|
||||||
}
|
}
|
||||||
ASSERT(m_selected_index < m_windows.size());
|
ASSERT(new_selected_index < m_windows.size());
|
||||||
auto* highlight_window = m_windows.at(m_selected_index).ptr();
|
|
||||||
|
select_window_at_index(new_selected_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowSwitcher::select_window_at_index(int index)
|
||||||
|
{
|
||||||
|
m_selected_index = index;
|
||||||
|
auto* highlight_window = m_windows.at(index).ptr();
|
||||||
ASSERT(highlight_window);
|
ASSERT(highlight_window);
|
||||||
WindowManager::the().set_highlight_window(highlight_window);
|
WindowManager::the().set_highlight_window(highlight_window);
|
||||||
draw();
|
draw();
|
||||||
WindowManager::the().invalidate(m_rect);
|
WindowManager::the().invalidate(m_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gfx::Rect WindowSwitcher::item_rect(int index) const
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
padding(),
|
||||||
|
padding() + index * item_height(),
|
||||||
|
m_rect.width() - padding() * 2,
|
||||||
|
item_height()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void WindowSwitcher::draw()
|
void WindowSwitcher::draw()
|
||||||
{
|
{
|
||||||
auto palette = WindowManager::the().palette();
|
auto palette = WindowManager::the().palette();
|
||||||
|
@ -117,12 +154,7 @@ void WindowSwitcher::draw()
|
||||||
painter.draw_rect({ {}, m_rect.size() }, palette.threed_shadow2());
|
painter.draw_rect({ {}, m_rect.size() }, palette.threed_shadow2());
|
||||||
for (int index = 0; index < m_windows.size(); ++index) {
|
for (int index = 0; index < m_windows.size(); ++index) {
|
||||||
auto& window = *m_windows.at(index);
|
auto& window = *m_windows.at(index);
|
||||||
Gfx::Rect item_rect {
|
auto item_rect = this->item_rect(index);
|
||||||
padding(),
|
|
||||||
padding() + index * item_height(),
|
|
||||||
m_rect.width() - padding() * 2,
|
|
||||||
item_height()
|
|
||||||
};
|
|
||||||
Color text_color;
|
Color text_color;
|
||||||
Color rect_text_color;
|
Color rect_text_color;
|
||||||
if (index == m_selected_index) {
|
if (index == m_selected_index) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace WindowServer {
|
||||||
class KeyEvent;
|
class KeyEvent;
|
||||||
class Window;
|
class Window;
|
||||||
|
|
||||||
class WindowSwitcher : public Core::Object {
|
class WindowSwitcher final : public Core::Object {
|
||||||
C_OBJECT(WindowSwitcher)
|
C_OBJECT(WindowSwitcher)
|
||||||
public:
|
public:
|
||||||
static WindowSwitcher& the();
|
static WindowSwitcher& the();
|
||||||
|
@ -55,23 +55,29 @@ public:
|
||||||
void hide() { set_visible(false); }
|
void hide() { set_visible(false); }
|
||||||
|
|
||||||
void on_key_event(const KeyEvent&);
|
void on_key_event(const KeyEvent&);
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
void refresh_if_needed();
|
void refresh_if_needed();
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
int thumbnail_width() { return 40; }
|
int thumbnail_width() const { return 40; }
|
||||||
int thumbnail_height() { return 40; }
|
int thumbnail_height() const { return 40; }
|
||||||
|
|
||||||
int item_height() { return 10 + thumbnail_height(); }
|
int item_height() const { return 10 + thumbnail_height(); }
|
||||||
int padding() { return 8; }
|
int padding() const { return 8; }
|
||||||
int item_padding() { return 8; }
|
int item_padding() const { return 8; }
|
||||||
|
|
||||||
Window* selected_window();
|
Window* selected_window();
|
||||||
|
|
||||||
Window* switcher_window() { return m_switcher_window.ptr(); }
|
Window* switcher_window() { return m_switcher_window.ptr(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void select_window_at_index(int index);
|
||||||
|
Gfx::Rect item_rect(int index) const;
|
||||||
|
|
||||||
|
virtual void event(Core::Event&) override;
|
||||||
|
|
||||||
RefPtr<Window> m_switcher_window;
|
RefPtr<Window> m_switcher_window;
|
||||||
Gfx::Rect m_rect;
|
Gfx::Rect m_rect;
|
||||||
bool m_visible { false };
|
bool m_visible { false };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue