WindowServer: Replace "Pin/Unpin Window" => "Always on Top"

This commit is contained in:
Andreas Kling 2021-11-13 12:18:14 +01:00
parent d21dc1f451
commit 68dc2e62fb
Notes: sideshowbarker 2024-07-18 01:12:35 +09:00
6 changed files with 30 additions and 33 deletions

View file

@ -288,9 +288,6 @@ void Window::update_window_menu_items()
m_window_menu_close_item->set_enabled(m_closeable);
m_window_menu_move_item->set_enabled(m_minimized_state == WindowMinimizedState::None && !m_maximized && !m_fullscreen);
if (m_window_menu_pin_item)
m_window_menu_pin_item->set_text(m_pinned ? "Un-&Pin Window" : "&Pin Window");
}
void Window::set_minimized(bool minimized)
@ -490,15 +487,15 @@ void Window::set_maximized(bool maximized, Optional<Gfx::IntPoint> fixed_point)
Core::EventLoop::current().post_event(*this, make<ResizeEvent>(m_rect));
set_default_positioned(false);
}
void Window::set_pinned(bool pinned)
void Window::set_always_on_top(bool always_on_top)
{
if (m_pinned == pinned)
if (m_always_on_top == always_on_top)
return;
m_pinned = pinned;
m_always_on_top = always_on_top;
update_window_menu_items();
window_stack().move_pinned_windows_to_front();
window_stack().move_always_on_top_windows_to_front();
Compositor::the().invalidate_occlusions();
}
void Window::set_vertically_maximized()
@ -809,10 +806,10 @@ void Window::ensure_window_menu()
m_window_menu->add_item(make<MenuItem>(*m_window_menu, MenuItem::Type::Separator));
if (!m_modal) {
auto pin_item = make<MenuItem>(*m_window_menu, (unsigned)WindowMenuAction::TogglePinned, "&Pin Window");
m_window_menu_pin_item = pin_item.ptr();
m_window_menu_pin_item->set_icon(&pin_icon());
m_window_menu_pin_item->set_checkable(true);
auto pin_item = make<MenuItem>(*m_window_menu, (unsigned)WindowMenuAction::ToggleAlwaysOnTop, "Always on &Top");
m_window_menu_always_on_top_item = pin_item.ptr();
m_window_menu_always_on_top_item->set_icon(&pin_icon());
m_window_menu_always_on_top_item->set_checkable(true);
m_window_menu->add_item(move(pin_item));
m_window_menu->add_item(make<MenuItem>(*m_window_menu, MenuItem::Type::Separator));
}
@ -859,11 +856,11 @@ void Window::handle_window_menu_action(WindowMenuAction action)
invalidate_last_rendered_screen_rects();
break;
}
case WindowMenuAction::TogglePinned: {
case WindowMenuAction::ToggleAlwaysOnTop: {
auto& item = *m_window_menu->item_by_identifier((unsigned)action);
auto new_is_checked = !item.is_checked();
item.set_checked(new_is_checked);
WindowManager::the().set_pinned(*this, new_is_checked);
WindowManager::the().set_always_on_top(*this, new_is_checked);
break;
}
}

View file

@ -56,7 +56,7 @@ enum class WindowMenuAction {
ToggleMenubarVisibility,
Close,
Move,
TogglePinned,
ToggleAlwaysOnTop,
};
enum class WindowMenuDefaultAction {
@ -107,8 +107,8 @@ public:
bool is_maximized() const { return m_maximized; }
void set_maximized(bool, Optional<Gfx::IntPoint> fixed_point = {});
bool is_pinned() const { return m_pinned; }
void set_pinned(bool);
bool is_always_on_top() const { return m_always_on_top; }
void set_always_on_top(bool);
void set_vertically_maximized();
@ -429,7 +429,7 @@ private:
bool m_invalidated_frame { true };
bool m_hit_testing_enabled { true };
bool m_modified { false };
bool m_pinned { false };
bool m_always_on_top { false };
bool m_moving_to_another_stack { false };
bool m_invalidate_last_render_rects { false };
Vector<i32> m_stealable_by_client_ids;
@ -459,7 +459,7 @@ private:
MenuItem* m_window_menu_maximize_item { nullptr };
MenuItem* m_window_menu_move_item { nullptr };
MenuItem* m_window_menu_close_item { nullptr };
MenuItem* m_window_menu_pin_item { nullptr };
MenuItem* m_window_menu_always_on_top_item { nullptr };
MenuItem* m_window_menu_menubar_visibility_item { nullptr };
Optional<int> m_progress;
bool m_should_show_menubar { true };

View file

@ -1994,10 +1994,10 @@ void WindowManager::maximize_windows(Window& window, bool maximized)
});
}
void WindowManager::set_pinned(Window& window, bool pinned)
void WindowManager::set_always_on_top(Window& window, bool always_on_top)
{
for_each_window_in_modal_stack(window, [&](auto& w, bool) {
w.set_pinned(pinned);
w.set_always_on_top(always_on_top);
return IterationDecision::Continue;
});
}

View file

@ -225,7 +225,7 @@ public:
void minimize_windows(Window&, bool);
void hide_windows(Window&, bool);
void maximize_windows(Window&, bool);
void set_pinned(Window&, bool);
void set_always_on_top(Window&, bool);
template<typename Function>
IterationDecision for_each_window_in_modal_stack(Window& window, Function f)

View file

@ -25,7 +25,7 @@ void WindowStack::add(Window& window)
m_windows.append(window);
window.set_window_stack({}, this);
move_pinned_windows_to_front();
move_always_on_top_windows_to_front();
}
void WindowStack::add_to_back(Window& window)
@ -56,30 +56,30 @@ void WindowStack::move_to_front(Window& window)
m_windows.remove(window);
m_windows.append(window);
move_pinned_windows_to_front();
move_always_on_top_windows_to_front();
if (window.is_pinned()) {
if (window.is_always_on_top()) {
m_windows.remove(window);
m_windows.append(window);
window.invalidate();
}
}
void WindowStack::move_pinned_windows_to_front()
void WindowStack::move_always_on_top_windows_to_front()
{
Window::List pinned_list;
Window::List always_on_top_list;
for (auto iterator = m_windows.begin(); iterator != m_windows.end(); ++iterator) {
auto& window = *iterator;
if (window.is_pinned()) {
if (window.is_always_on_top()) {
m_windows.remove(window);
pinned_list.append(window);
always_on_top_list.append(window);
iterator = m_windows.begin();
}
}
while (!pinned_list.is_empty()) {
auto& window = *pinned_list.begin();
pinned_list.remove(window);
while (!always_on_top_list.is_empty()) {
auto& window = *always_on_top_list.begin();
always_on_top_list.remove(window);
m_windows.append(window);
window.invalidate();
}
@ -89,7 +89,7 @@ void WindowStack::move_all_windows(WindowStack& new_window_stack, Vector<Window*
{
VERIFY(this != &new_window_stack);
move_pinned_windows_to_front();
move_always_on_top_windows_to_front();
if (move_to == MoveAllWindowsTo::Front) {
while (auto* window = m_windows.take_first()) {

View file

@ -23,7 +23,7 @@ public:
void add_to_back(Window&);
void remove(Window&);
void move_to_front(Window&);
void move_pinned_windows_to_front();
void move_always_on_top_windows_to_front();
enum class MoveAllWindowsTo {
Front,