Skip to content

Commit

Permalink
Implement minimization
Browse files Browse the repository at this point in the history
  • Loading branch information
serebit committed Oct 13, 2023
1 parent 16b4b7b commit 25d074f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 21 deletions.
5 changes: 4 additions & 1 deletion src/input/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "surface.hpp"
#include "view.hpp"

#include <iostream>

#include "wlr-wrap-start.hpp"
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/types/wlr_pointer.h>
Expand Down Expand Up @@ -134,7 +136,8 @@ static void cursor_button_notify(wl_listener* listener, void* data) {
/* Notify the client with pointer focus that a button press has occurred */
wlr_seat_pointer_notify_button(server.seat->seat, event->time_msec, event->button, event->state);
double sx, sy;
wlr_surface* surface = NULL;

wlr_surface* surface = nullptr;
Surface* magpie_surface = server.surface_at(cursor.cursor->x, cursor.cursor->y, &surface, &sx, &sy);

if (event->state == WLR_BUTTON_RELEASED) {
Expand Down
23 changes: 20 additions & 3 deletions src/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void View::set_activated(const bool activated) {

void View::set_maximized(const bool maximized) {
Server& server = get_server();
if (this->maximized == maximized) {
if (this->is_maximized == maximized) {
/* Don't honor request if already maximized. */
return;
}
Expand All @@ -115,7 +115,7 @@ void View::set_maximized(const bool maximized) {
return;
}

if (this->maximized) {
if (this->is_maximized) {
set_size(previous.width, previous.height);
impl_set_maximized(false);
current.x = previous.x;
Expand All @@ -140,6 +140,23 @@ void View::set_maximized(const bool maximized) {
wlr_scene_node_set_position(scene_node, current.x, current.y);
}

this->maximized = maximized;
this->is_maximized = maximized;
toplevel_handle->set_maximized(maximized);
}

void View::set_minimized(const bool minimized) {
if (minimized == is_minimized) {
return;
}

toplevel_handle->set_minimized(minimized);
impl_set_minimized(minimized);
this->is_minimized = minimized;

if (minimized) {
unmap();
set_activated(false);
} else {
map();
}
}
35 changes: 20 additions & 15 deletions src/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#include "wlr-wrap-end.hpp"

struct View : public Surface {
bool maximized;
bool is_maximized;
bool is_minimized;
wlr_box current;
wlr_box pending;
wlr_box previous;
Expand All @@ -32,6 +33,7 @@ struct View : public Surface {
void set_size(const int new_width, const int new_height);
void set_activated(const bool activated);
void set_maximized(const bool maximized);
void set_minimized(const bool minimized);

private:
const std::optional<const Output*> find_output_for_maximize();
Expand All @@ -40,6 +42,7 @@ struct View : public Surface {
virtual void impl_set_size(const int new_width, const int new_height) = 0;
virtual void impl_set_activated(const bool activated) = 0;
virtual void impl_set_maximized(const bool maximized) = 0;
virtual void impl_set_minimized(bool minimized) = 0;
};

class XdgView : public View {
Expand Down Expand Up @@ -71,15 +74,16 @@ class XdgView : public View {
XdgView(Server& server, wlr_xdg_toplevel& toplevel) noexcept;
~XdgView() noexcept;

inline Server& get_server() const;
const wlr_box get_geometry() const;
void map();
void unmap();
inline Server& get_server() const override;
const wlr_box get_geometry() const override;
void map() override;
void unmap() override;

protected:
void impl_set_size(int new_width, int new_height);
void impl_set_activated(bool activated);
void impl_set_maximized(bool maximized);
void impl_set_size(int new_width, int new_height) override;
void impl_set_activated(bool activated) override;
void impl_set_maximized(bool maximized) override;
void impl_set_minimized(bool minimized) override;
};

class XWaylandView : public View {
Expand Down Expand Up @@ -110,15 +114,16 @@ class XWaylandView : public View {
XWaylandView(Server& server, wlr_xwayland_surface& surface) noexcept;
~XWaylandView() noexcept;

inline Server& get_server() const;
const wlr_box get_geometry() const;
void map();
void unmap();
inline Server& get_server() const override;
const wlr_box get_geometry() const override;
void map() override;
void unmap() override;

protected:
void impl_set_size(int new_width, int new_height);
void impl_set_activated(bool activated);
void impl_set_maximized(bool maximized);
void impl_set_size(int new_width, int new_height) override;
void impl_set_activated(bool activated) override;
void impl_set_maximized(bool maximized) override;
void impl_set_minimized(bool minimized) override;
};

#endif
8 changes: 6 additions & 2 deletions src/xdg_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void xdg_toplevel_request_maximize_notify(wl_listener* listener, void* da
XdgView& view = magpie_container_of(listener, view, request_maximize);
(void) data;

view.set_maximized(!view.maximized);
view.set_maximized(!view.is_maximized);
wlr_xdg_surface_schedule_configure(view.xdg_toplevel.base);
}

Expand Down Expand Up @@ -183,7 +183,7 @@ const wlr_box XdgView::get_geometry() const {

void XdgView::map() {
wlr_scene_node_set_enabled(scene_node, true);
maximized = xdg_toplevel.current.maximized;
is_maximized = xdg_toplevel.current.maximized;
server.focus_view(*this, xdg_toplevel.base->surface);
}

Expand All @@ -207,3 +207,7 @@ void XdgView::impl_set_activated(const bool activated) {
void XdgView::impl_set_maximized(const bool maximized) {
wlr_xdg_toplevel_set_maximized(&xdg_toplevel, maximized);
}

void XdgView::impl_set_minimized(const bool minimized) {
(void) minimized;
}
4 changes: 4 additions & 0 deletions src/xwayland_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,7 @@ void XWaylandView::impl_set_activated(bool activated) {
void XWaylandView::impl_set_maximized(const bool maximized) {
wlr_xwayland_surface_set_maximized(&xwayland_surface, maximized);
}

void XWaylandView::impl_set_minimized(const bool minimized) {
wlr_xwayland_surface_set_minimized(&xwayland_surface, minimized);
}

0 comments on commit 25d074f

Please sign in to comment.