From 945b425007f0e368993c0063ea89d12697c3fc3a Mon Sep 17 00:00:00 2001 From: Campbell Jones Date: Fri, 10 Nov 2023 17:23:02 -0500 Subject: [PATCH] Apply clang-tidy suggestions to all source files --- src/foreign_toplevel.cpp | 34 +++++------ src/foreign_toplevel.hpp | 36 ++++++------ src/input/constraint.hpp | 8 +-- src/input/cursor.cpp | 83 +++++++++++++------------- src/input/cursor.hpp | 44 +++++++------- src/input/keyboard.cpp | 27 +++++---- src/input/keyboard.hpp | 8 +-- src/input/seat.cpp | 12 ++-- src/input/seat.hpp | 16 ++--- src/output.cpp | 31 +++++----- src/output.hpp | 24 ++++---- src/server.cpp | 68 +++++++++++---------- src/server.hpp | 29 +++++---- src/surface/layer.cpp | 14 ++--- src/surface/layer.hpp | 36 ++++++------ src/surface/popup.hpp | 24 ++++---- src/surface/surface.hpp | 8 +-- src/surface/view.cpp | 37 ++++++------ src/surface/view.hpp | 108 +++++++++++++++++----------------- src/surface/xdg_view.cpp | 20 +++---- src/surface/xwayland_view.cpp | 72 ++++++++++++----------- src/xwayland.cpp | 13 ++-- src/xwayland.hpp | 14 ++--- 23 files changed, 390 insertions(+), 376 deletions(-) diff --git a/src/foreign_toplevel.cpp b/src/foreign_toplevel.cpp index 174d96131..517c77164 100644 --- a/src/foreign_toplevel.cpp +++ b/src/foreign_toplevel.cpp @@ -6,23 +6,23 @@ static void foreign_toplevel_handle_request_maximize_notify(wl_listener* listener, void* data) { const ForeignToplevelHandle& handle = magpie_container_of(listener, handle, request_activate); - auto& event = *static_cast(data); + const auto& event = *static_cast(data); - auto placement = event.maximized ? VIEW_PLACEMENT_MAXIMIZED : VIEW_PLACEMENT_STACKING; + const auto placement = event.maximized ? VIEW_PLACEMENT_MAXIMIZED : VIEW_PLACEMENT_STACKING; handle.view.set_placement(placement); } static void foreign_toplevel_handle_request_fullscreen_notify(wl_listener* listener, void* data) { const ForeignToplevelHandle& handle = magpie_container_of(listener, handle, request_activate); - auto& event = *static_cast(data); + const auto& event = *static_cast(data); - auto placement = event.maximized ? VIEW_PLACEMENT_FULLSCREEN : VIEW_PLACEMENT_STACKING; + const auto placement = event.maximized ? VIEW_PLACEMENT_FULLSCREEN : VIEW_PLACEMENT_STACKING; handle.view.set_placement(placement); } static void foreign_toplevel_handle_request_minimize_notify(wl_listener* listener, void* data) { const ForeignToplevelHandle& handle = magpie_container_of(listener, handle, request_activate); - auto& event = *static_cast(data); + const auto& event = *static_cast(data); handle.view.set_minimized(event.minimized); } @@ -42,7 +42,7 @@ static void foreign_toplevel_handle_request_close_notify(wl_listener* listener, static void foreign_toplevel_handle_set_rectangle_notify(wl_listener* listener, void* data) { const ForeignToplevelHandle& handle = magpie_container_of(listener, handle, set_rectangle); - auto& event = *static_cast(data); + const auto& event = *static_cast(data); handle.view.set_position(event.x, event.y); handle.view.set_size(event.width, event.height); @@ -76,47 +76,47 @@ ForeignToplevelHandle::~ForeignToplevelHandle() noexcept { wl_list_remove(&listeners.set_rectangle.link); } -void ForeignToplevelHandle::set_title(const char* title) { +void ForeignToplevelHandle::set_title(const char* title) const { if (title != nullptr) { wlr_foreign_toplevel_handle_v1_set_title(&handle, title); } } -void ForeignToplevelHandle::set_app_id(const char* app_id) { +void ForeignToplevelHandle::set_app_id(const char* app_id) const { if (app_id != nullptr) { wlr_foreign_toplevel_handle_v1_set_app_id(&handle, app_id); } } -void ForeignToplevelHandle::set_parent(std::optional> parent) { - wlr_foreign_toplevel_handle_v1_set_parent(&handle, (parent.has_value()) ? nullptr : &parent->get().handle); +void ForeignToplevelHandle::set_parent(const std::optional> parent) const { + wlr_foreign_toplevel_handle_v1_set_parent(&handle, parent.has_value() ? nullptr : &parent->get().handle); } -void ForeignToplevelHandle::set_placement(const ViewPlacement placement) { +void ForeignToplevelHandle::set_placement(const ViewPlacement placement) const { set_maximized(placement == VIEW_PLACEMENT_MAXIMIZED); set_fullscreen(placement == VIEW_PLACEMENT_FULLSCREEN); } -void ForeignToplevelHandle::set_maximized(const bool maximized) { +void ForeignToplevelHandle::set_maximized(const bool maximized) const { wlr_foreign_toplevel_handle_v1_set_maximized(&handle, maximized); } -void ForeignToplevelHandle::set_minimized(const bool minimized) { +void ForeignToplevelHandle::set_minimized(const bool minimized) const { wlr_foreign_toplevel_handle_v1_set_minimized(&handle, minimized); } -void ForeignToplevelHandle::set_activated(const bool activated) { +void ForeignToplevelHandle::set_activated(const bool activated) const { wlr_foreign_toplevel_handle_v1_set_activated(&handle, activated); } -void ForeignToplevelHandle::set_fullscreen(const bool fullscreen) { +void ForeignToplevelHandle::set_fullscreen(const bool fullscreen) const { wlr_foreign_toplevel_handle_v1_set_fullscreen(&handle, fullscreen); } -void ForeignToplevelHandle::output_enter(const Output& output) { +void ForeignToplevelHandle::output_enter(const Output& output) const { wlr_foreign_toplevel_handle_v1_output_enter(&handle, &output.wlr); } -void ForeignToplevelHandle::output_leave(const Output& output) { +void ForeignToplevelHandle::output_leave(const Output& output) const { wlr_foreign_toplevel_handle_v1_output_leave(&handle, &output.wlr); } diff --git a/src/foreign_toplevel.hpp b/src/foreign_toplevel.hpp index e41042428..686d114be 100644 --- a/src/foreign_toplevel.hpp +++ b/src/foreign_toplevel.hpp @@ -14,13 +14,13 @@ class ForeignToplevelHandle { public: struct Listeners { std::reference_wrapper parent; - wl_listener request_maximize; - wl_listener request_minimize; - wl_listener request_activate; - wl_listener request_fullscreen; - wl_listener request_close; - wl_listener set_rectangle; - Listeners(ForeignToplevelHandle& parent) noexcept : parent(parent) {} + wl_listener request_maximize = {}; + wl_listener request_minimize = {}; + wl_listener request_activate = {}; + wl_listener request_fullscreen = {}; + wl_listener request_close = {}; + wl_listener set_rectangle = {}; + explicit Listeners(ForeignToplevelHandle& parent) noexcept : parent(parent) {} }; private: @@ -30,19 +30,19 @@ class ForeignToplevelHandle { View& view; wlr_foreign_toplevel_handle_v1& handle; - ForeignToplevelHandle(View& view) noexcept; + explicit ForeignToplevelHandle(View& view) noexcept; ~ForeignToplevelHandle() noexcept; - void set_title(const char* title); - void set_app_id(const char* app_id); - void set_parent(std::optional> parent); - void set_placement(const ViewPlacement placement); - void set_maximized(const bool maximized); - void set_fullscreen(const bool fullscreen); - void set_minimized(const bool minimized); - void set_activated(const bool activated); - void output_enter(const Output& output); - void output_leave(const Output& output); + void set_title(const char* title) const; + void set_app_id(const char* app_id) const; + void set_parent(std::optional> parent) const; + void set_placement(ViewPlacement placement) const; + void set_maximized(bool maximized) const; + void set_fullscreen(bool fullscreen) const; + void set_minimized(bool minimized) const; + void set_activated(bool activated) const; + void output_enter(const Output& output) const; + void output_leave(const Output& output) const; }; #endif diff --git a/src/input/constraint.hpp b/src/input/constraint.hpp index 4a217022e..3e2041ee8 100644 --- a/src/input/constraint.hpp +++ b/src/input/constraint.hpp @@ -14,10 +14,10 @@ class PointerConstraint { public: struct Listeners { std::reference_wrapper parent; - wl_listener set_region; - wl_listener surface_commit; - wl_listener destroy; - Listeners(PointerConstraint& parent) noexcept : parent(parent) {} + wl_listener set_region = {}; + wl_listener surface_commit = {}; + wl_listener destroy = {}; + explicit Listeners(PointerConstraint& parent) noexcept : parent(parent) {} }; private: diff --git a/src/input/cursor.cpp b/src/input/cursor.cpp index e41cd2f9d..abf17c729 100644 --- a/src/input/cursor.cpp +++ b/src/input/cursor.cpp @@ -14,11 +14,10 @@ #include #include #include -#include #include #include "wlr-wrap-end.hpp" -void Cursor::process_resize(const uint32_t time) { +void Cursor::process_resize(const uint32_t time) const { (void) time; /* @@ -32,41 +31,41 @@ void Cursor::process_resize(const uint32_t time) { * commit any movement that was prepared. */ View& view = *seat.server.grabbed_view; - double border_x = wlr.x - seat.server.grab_x; - double border_y = wlr.y - seat.server.grab_y; + const double border_x = wlr.x - seat.server.grab_x; + const double border_y = wlr.y - seat.server.grab_y; int new_left = seat.server.grab_geobox.x; int new_right = seat.server.grab_geobox.x + seat.server.grab_geobox.width; int new_top = seat.server.grab_geobox.y; int new_bottom = seat.server.grab_geobox.y + seat.server.grab_geobox.height; if (seat.server.resize_edges & WLR_EDGE_TOP) { - new_top = border_y; + new_top = static_cast(std::round(border_y)); if (new_top >= new_bottom) { new_top = new_bottom - 1; } } else if (seat.server.resize_edges & WLR_EDGE_BOTTOM) { - new_bottom = border_y; + new_bottom = static_cast(std::round(border_y)); if (new_bottom <= new_top) { new_bottom = new_top + 1; } } if (seat.server.resize_edges & WLR_EDGE_LEFT) { - new_left = border_x; + new_left = static_cast(std::round(border_x)); if (new_left >= new_right) { new_left = new_right - 1; } } else if (seat.server.resize_edges & WLR_EDGE_RIGHT) { - new_right = border_x; + new_right = static_cast(std::round(border_x)); if (new_right <= new_left) { new_right = new_left + 1; } } - wlr_box geo_box = view.get_geometry(); + const wlr_box geo_box = view.get_geometry(); view.set_position(new_left - geo_box.x, new_top - geo_box.y); - int new_width = new_right - new_left; - int new_height = new_bottom - new_top; + const int new_width = new_right - new_left; + const int new_height = new_bottom - new_top; view.set_size(new_width, new_height); } @@ -75,8 +74,8 @@ void Cursor::process_move(const uint32_t time) { /* Move the grabbed view to the new position. */ View* view = seat.server.grabbed_view; - view->current.x = wlr.x - seat.server.grab_x; - view->current.y = fmax(wlr.y - seat.server.grab_y, 0); + view->current.x = static_cast(std::round(wlr.x - seat.server.grab_x)); + view->current.y = static_cast(std::round(std::fmax(wlr.y - seat.server.grab_y, 0))); set_image("fleur"); wlr_scene_node_set_position(view->scene_node, view->current.x, view->current.y); @@ -86,7 +85,7 @@ void Cursor::process_move(const uint32_t time) { * for example when you move the scroll wheel. */ static void cursor_axis_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, axis); - auto* event = static_cast(data); + const auto* event = static_cast(data); /* Notify the client with pointer focus of the axis event. */ wlr_seat_pointer_notify_axis( @@ -113,7 +112,7 @@ static void cursor_frame_notify(wl_listener* listener, void* data) { * emits these events. */ static void cursor_motion_absolute_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, motion_absolute); - auto* event = static_cast(data); + const auto* event = static_cast(data); double lx, ly; wlr_cursor_absolute_to_layout_coords(&cursor.wlr, &event->pointer->base, event->x, event->y, &lx, &ly); @@ -121,7 +120,7 @@ static void cursor_motion_absolute_notify(wl_listener* listener, void* data) { double dx = lx - cursor.wlr.x; double dy = ly - cursor.wlr.y; wlr_relative_pointer_manager_v1_send_relative_motion( - cursor.relative_pointer_mgr, cursor.seat.wlr, (uint64_t) event->time_msec * 1000, dx, dy, dx, dy); + cursor.relative_pointer_mgr, cursor.seat.wlr, static_cast(event->time_msec) * 1000, dx, dy, dx, dy); if (cursor.seat.is_pointer_locked(event->pointer)) { return; @@ -136,7 +135,7 @@ static void cursor_motion_absolute_notify(wl_listener* listener, void* data) { /* This event is forwarded by the cursor when a pointer emits a button event. */ static void cursor_button_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, button); - auto* event = static_cast(data); + const auto* event = static_cast(data); Server& server = cursor.seat.server; @@ -154,7 +153,7 @@ static void cursor_button_notify(wl_listener* listener, void* data) { } } else if (magpie_surface != nullptr && magpie_surface->is_view()) { /* Focus that client if the button was _pressed_ */ - server.focus_view(static_cast(magpie_surface), surface); + server.focus_view(dynamic_cast(magpie_surface), surface); } else { server.focus_view(nullptr); } @@ -164,10 +163,10 @@ static void cursor_button_notify(wl_listener* listener, void* data) { * pointer motion event (i.e. a delta) */ static void cursor_motion_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, motion); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_relative_pointer_manager_v1_send_relative_motion(cursor.relative_pointer_mgr, cursor.seat.wlr, - (uint64_t) event->time_msec * 1000, event->delta_x, event->delta_y, event->unaccel_dx, event->unaccel_dy); + static_cast(event->time_msec) * 1000, event->delta_x, event->delta_y, event->unaccel_dx, event->unaccel_dy); if (cursor.seat.is_pointer_locked(event->pointer)) { return; @@ -183,14 +182,14 @@ static void cursor_motion_notify(wl_listener* listener, void* data) { static void gesture_pinch_begin_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, gesture_pinch_begin); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_pointer_gestures_v1_send_pinch_begin(cursor.pointer_gestures, cursor.seat.wlr, event->time_msec, event->fingers); } static void gesture_pinch_update_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, gesture_pinch_update); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_pointer_gestures_v1_send_pinch_update( cursor.pointer_gestures, cursor.seat.wlr, event->time_msec, event->dx, event->dy, event->scale, event->rotation); @@ -198,42 +197,42 @@ static void gesture_pinch_update_notify(wl_listener* listener, void* data) { static void gesture_pinch_end_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, gesture_pinch_end); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_pointer_gestures_v1_send_pinch_end(cursor.pointer_gestures, cursor.seat.wlr, event->time_msec, event->cancelled); } static void gesture_swipe_begin_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, gesture_swipe_begin); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_pointer_gestures_v1_send_swipe_begin(cursor.pointer_gestures, cursor.seat.wlr, event->time_msec, event->fingers); } static void gesture_swipe_update_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, gesture_swipe_update); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_pointer_gestures_v1_send_swipe_update(cursor.pointer_gestures, cursor.seat.wlr, event->time_msec, event->dx, event->dy); } static void gesture_swipe_end_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, gesture_swipe_end); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_pointer_gestures_v1_send_swipe_end(cursor.pointer_gestures, cursor.seat.wlr, event->time_msec, event->cancelled); } static void gesture_hold_begin_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, gesture_hold_begin); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_pointer_gestures_v1_send_hold_begin(cursor.pointer_gestures, cursor.seat.wlr, event->time_msec, event->fingers); } static void gesture_hold_end_notify(wl_listener* listener, void* data) { Cursor& cursor = magpie_container_of(listener, cursor, gesture_hold_end); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_pointer_gestures_v1_send_hold_end(cursor.pointer_gestures, cursor.seat.wlr, event->time_msec, event->cancelled); } @@ -249,7 +248,7 @@ Cursor::Cursor(Seat& seat) noexcept : listeners(*this), seat(seat), wlr(*wlr_cur * Xcursor themes to source cursor images from and makes sure that cursor * images are available at all scale factors on the screen (necessary for * HiDPI support). We add a cursor theme at scale factor 1 to begin with. */ - cursor_mgr = wlr_xcursor_manager_create(NULL, 24); + cursor_mgr = wlr_xcursor_manager_create(nullptr, 24); wlr_xcursor_manager_load(cursor_mgr, 1); relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(seat.server.display); @@ -297,7 +296,7 @@ Cursor::Cursor(Seat& seat) noexcept : listeners(*this), seat(seat), wlr(*wlr_cur wl_signal_add(&wlr.events.hold_end, &listeners.gesture_swipe_end); } -void Cursor::attach_input_device(wlr_input_device* device) { +void Cursor::attach_input_device(wlr_input_device* device) const { wlr_cursor_attach_input_device(&wlr, device); } @@ -308,7 +307,9 @@ void Cursor::process_motion(const uint32_t time) { if (mode == MAGPIE_CURSOR_MOVE) { process_move(time); return; - } else if (mode == MAGPIE_CURSOR_RESIZE) { + } + + if (mode == MAGPIE_CURSOR_RESIZE) { process_resize(time); return; } @@ -316,7 +317,7 @@ void Cursor::process_motion(const uint32_t time) { /* Otherwise, find the view under the pointer and send the event along. */ double sx, sy; wlr_surface* surface = nullptr; - Surface* magpie_surface = seat.server.surface_at(wlr.x, wlr.y, &surface, &sx, &sy); + const Surface* magpie_surface = seat.server.surface_at(wlr.x, wlr.y, &surface, &sx, &sy); if (magpie_surface == nullptr) { /* If there's no view under the cursor, set the cursor image to a * default. This is what makes the cursor image appear when you move it @@ -351,35 +352,35 @@ void Cursor::reset_mode() { set_image("left_ptr"); } mode = MAGPIE_CURSOR_PASSTHROUGH; - seat.server.grabbed_view = NULL; + seat.server.grabbed_view = nullptr; } -void Cursor::warp_to_constraint(PointerConstraint& constraint) { - if (seat.server.focused_view->get_wlr_surface() != constraint.wlr.surface) { +void Cursor::warp_to_constraint(PointerConstraint& constraint) const { + if (seat.server.focused_view == nullptr) { + // only warp to constraints tied to views... return; } - if (seat.server.focused_view == nullptr) { - // only warp to constraints tied to views... + if (seat.server.focused_view->get_wlr_surface() != constraint.wlr.surface) { return; } if (constraint.wlr.current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { - double x = constraint.wlr.current.cursor_hint.x; - double y = constraint.wlr.current.cursor_hint.y; + const double x = constraint.wlr.current.cursor_hint.x; + const double y = constraint.wlr.current.cursor_hint.y; wlr_cursor_warp(&wlr, nullptr, seat.server.focused_view->current.x + x, seat.server.focused_view->current.y + y); wlr_seat_pointer_warp(seat.wlr, x, y); } } -void Cursor::set_image(const std::string name) { +void Cursor::set_image(const std::string& name) { if (current_image != name) { current_image = name; reload_image(); } } -void Cursor::reload_image() { +void Cursor::reload_image() const { wlr_xcursor_manager_set_cursor_image(cursor_mgr, current_image.c_str(), &wlr); } diff --git a/src/input/cursor.hpp b/src/input/cursor.hpp index e0164c0bc..55b5f3ec7 100644 --- a/src/input/cursor.hpp +++ b/src/input/cursor.hpp @@ -20,28 +20,28 @@ class Cursor { public: struct Listeners { std::reference_wrapper parent; - wl_listener motion; - wl_listener motion_absolute; - wl_listener button; - wl_listener axis; - wl_listener frame; - wl_listener new_constraint; - wl_listener gesture_pinch_begin; - wl_listener gesture_pinch_update; - wl_listener gesture_pinch_end; - wl_listener gesture_swipe_begin; - wl_listener gesture_swipe_update; - wl_listener gesture_swipe_end; - wl_listener gesture_hold_begin; - wl_listener gesture_hold_end; - Listeners(Cursor& parent) noexcept : parent(parent) {} + wl_listener motion = {}; + wl_listener motion_absolute = {}; + wl_listener button = {}; + wl_listener axis = {}; + wl_listener frame = {}; + wl_listener new_constraint = {}; + wl_listener gesture_pinch_begin = {}; + wl_listener gesture_pinch_update = {}; + wl_listener gesture_pinch_end = {}; + wl_listener gesture_swipe_begin = {}; + wl_listener gesture_swipe_update = {}; + wl_listener gesture_swipe_end = {}; + wl_listener gesture_hold_begin = {}; + wl_listener gesture_hold_end = {}; + explicit Listeners(Cursor& parent) noexcept : parent(parent) {} }; private: Listeners listeners; void process_move(uint32_t time); - void process_resize(uint32_t time); + void process_resize(uint32_t time) const; public: const Seat& seat; @@ -51,16 +51,16 @@ class Cursor { wlr_xcursor_manager* cursor_mgr; wlr_relative_pointer_manager_v1* relative_pointer_mgr; wlr_pointer_gestures_v1* pointer_gestures; - std::string current_image = ""; + std::string current_image; - Cursor(Seat& seat) noexcept; + explicit Cursor(Seat& seat) noexcept; - void attach_input_device(wlr_input_device* device); + void attach_input_device(wlr_input_device* device) const; void process_motion(uint32_t time); void reset_mode(); - void warp_to_constraint(PointerConstraint& constraint); - void set_image(const std::string name); - void reload_image(); + void warp_to_constraint(PointerConstraint& constraint) const; + void set_image(const std::string& name); + void reload_image() const; }; #endif diff --git a/src/input/keyboard.cpp b/src/input/keyboard.cpp index 24d588ae9..99d67539a 100644 --- a/src/input/keyboard.cpp +++ b/src/input/keyboard.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include "wlr-wrap-end.hpp" /* This event is raised by the keyboard base wlr_input_device to signal @@ -22,7 +21,7 @@ static void keyboard_handle_destroy(wl_listener* listener, void* data) { (void) data; std::vector& keyboards = keyboard.seat.keyboards; - (void) std::remove(keyboards.begin(), keyboards.end(), &keyboard); + (void) std::ranges::remove(keyboards, &keyboard).begin(); delete &keyboard; } @@ -32,10 +31,11 @@ static bool handle_compositor_keybinding(const Keyboard& keyboard, const uint32_ if (modifiers == WLR_MODIFIER_ALT) { switch (sym) { - case XKB_KEY_Escape: + case XKB_KEY_Escape: { wl_display_terminate(server.display); return true; - case XKB_KEY_Tab: + } + case XKB_KEY_Tab: { /* Cycle to the next view */ if (server.views.size() < 2) { return true; @@ -43,12 +43,15 @@ static bool handle_compositor_keybinding(const Keyboard& keyboard, const uint32_ View* next_view = *server.views.begin()++; server.focus_view(next_view); return true; + } + default: { + break; + } } } else if (sym >= XKB_KEY_XF86Switch_VT_1 && sym <= XKB_KEY_XF86Switch_VT_12) { if (wlr_backend_is_multi(keyboard.seat.server.backend)) { - wlr_session* session = wlr_backend_get_session(keyboard.seat.server.backend); - if (session) { - unsigned vt = sym - XKB_KEY_XF86Switch_VT_1 + 1; + if (wlr_session* session = wlr_backend_get_session(keyboard.seat.server.backend)) { + const unsigned vt = sym - XKB_KEY_XF86Switch_VT_1 + 1; wlr_session_change_vt(session, vt); } } @@ -62,19 +65,19 @@ static bool handle_compositor_keybinding(const Keyboard& keyboard, const uint32_ static void keyboard_handle_key(wl_listener* listener, void* data) { const Keyboard& keyboard = magpie_container_of(listener, keyboard, key); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_seat* seat = keyboard.seat.wlr; wlr_idle_notifier_v1_notify_activity(keyboard.seat.server.idle_notifier, seat); /* Translate libinput keycode -> xkbcommon */ - uint32_t keycode = event->keycode + 8; + const uint32_t keycode = event->keycode + 8; /* Get a list of keysyms based on the keymap for this keyboard */ const xkb_keysym_t* syms; - int nsyms = xkb_state_key_get_syms(keyboard.wlr.xkb_state, keycode, &syms); + const int nsyms = xkb_state_key_get_syms(keyboard.wlr.xkb_state, keycode, &syms); bool handled = false; - uint32_t modifiers = wlr_keyboard_get_modifiers(&keyboard.wlr); + const uint32_t modifiers = wlr_keyboard_get_modifiers(&keyboard.wlr); if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) { if (modifiers & WLR_MODIFIER_ALT) { /* If alt is held down and this button was _pressed_, we attempt to @@ -113,7 +116,7 @@ Keyboard::Keyboard(Seat& seat, wlr_keyboard& keyboard) noexcept : listeners(*thi /* We need to prepare an XKB keymap and assign it to the keyboard. This * assumes the defaults (e.g. layout = "us"). */ xkb_context* context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - xkb_keymap* keymap = xkb_keymap_new_from_names(context, NULL, XKB_KEYMAP_COMPILE_NO_FLAGS); + xkb_keymap* keymap = xkb_keymap_new_from_names(context, nullptr, XKB_KEYMAP_COMPILE_NO_FLAGS); wlr_keyboard_set_keymap(&keyboard, keymap); xkb_keymap_unref(keymap); diff --git a/src/input/keyboard.hpp b/src/input/keyboard.hpp index f9d535718..ee577dc41 100644 --- a/src/input/keyboard.hpp +++ b/src/input/keyboard.hpp @@ -13,10 +13,10 @@ class Keyboard { public: struct Listeners { std::reference_wrapper parent; - wl_listener modifiers; - wl_listener key; - wl_listener destroy; - Listeners(Keyboard& parent) noexcept : parent(parent) {} + wl_listener modifiers = {}; + wl_listener key = {}; + wl_listener destroy = {}; + explicit Listeners(Keyboard& parent) noexcept : parent(parent) {} }; private: diff --git a/src/input/seat.cpp b/src/input/seat.cpp index d96a76612..bfabb8352 100644 --- a/src/input/seat.cpp +++ b/src/input/seat.cpp @@ -27,7 +27,7 @@ static void new_input_notify(wl_listener* listener, void* data) { static void new_virtual_pointer_notify(wl_listener* listener, void* data) { Seat& seat = magpie_container_of(listener, seat, new_virtual_pointer); - auto* event = static_cast(data); + const auto* event = static_cast(data); seat.new_input_device(&event->new_pointer->pointer.base); } @@ -43,7 +43,7 @@ static void new_pointer_constraint_notify(wl_listener* listener, void* data) { Seat& seat = magpie_container_of(listener, seat, new_pointer_constraint); auto* wlr_constraint = static_cast(data); - auto* focused_surface = seat.wlr->keyboard_state.focused_surface; + const auto* focused_surface = seat.wlr->keyboard_state.focused_surface; if (focused_surface == wlr_constraint->surface) { // only allow creating constraints for the focused view seat.set_constraint(wlr_constraint); @@ -52,9 +52,9 @@ static void new_pointer_constraint_notify(wl_listener* listener, void* data) { static void request_cursor_notify(wl_listener* listener, void* data) { const Seat& seat = magpie_container_of(listener, seat, request_cursor); - auto* event = static_cast(data); + const auto* event = static_cast(data); - wlr_seat_client* focused_client = seat.wlr->pointer_state.focused_client; + const wlr_seat_client* focused_client = seat.wlr->pointer_state.focused_client; if (focused_client == event->seat_client) { /* Once we've vetted the client, we can tell the cursor to use the @@ -71,7 +71,7 @@ static void request_cursor_notify(wl_listener* listener, void* data) { */ static void request_set_selection_notify(wl_listener* listener, void* data) { const Seat& seat = magpie_container_of(listener, seat, request_set_selection); - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_seat_set_selection(seat.wlr, event->source, event->serial); } @@ -138,7 +138,7 @@ void Seat::set_constraint(wlr_pointer_constraint_v1* wlr_constraint) { } if (wlr_constraint != nullptr) { - current_constraint = *(new PointerConstraint(*this, *wlr_constraint)); + current_constraint = *new PointerConstraint(*this, *wlr_constraint); current_constraint.value().get().activate(); } } diff --git a/src/input/seat.hpp b/src/input/seat.hpp index 02acb90e4..e9497545d 100644 --- a/src/input/seat.hpp +++ b/src/input/seat.hpp @@ -19,13 +19,13 @@ class Seat { public: struct Listeners { std::reference_wrapper parent; - wl_listener new_input; - wl_listener new_virtual_pointer; - wl_listener new_virtual_keyboard; - wl_listener new_pointer_constraint; - wl_listener request_cursor; - wl_listener request_set_selection; - Listeners(Seat& parent) noexcept : parent(parent) {} + wl_listener new_input = {}; + wl_listener new_virtual_pointer = {}; + wl_listener new_virtual_keyboard = {}; + wl_listener new_pointer_constraint = {}; + wl_listener request_cursor = {}; + wl_listener request_set_selection = {}; + explicit Listeners(Seat& parent) noexcept : parent(parent) {} }; private: @@ -41,7 +41,7 @@ class Seat { wlr_pointer_constraints_v1* pointer_constraints; std::optional> current_constraint = {}; - Seat(Server& server) noexcept; + explicit Seat(Server& server) noexcept; ~Seat() noexcept; void new_input_device(wlr_input_device* device); diff --git a/src/output.cpp b/src/output.cpp index 5b255b826..13415b740 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -5,9 +5,11 @@ #include "types.hpp" #include +#include #include #include +#include #include static void output_enable_notify(wl_listener* listener, void* data) { @@ -32,19 +34,20 @@ static void output_frame_notify(wl_listener* listener, void* data) { Output& output = magpie_container_of(listener, output, frame); (void) data; + if (output.scene_output == nullptr) { + output.scene_output = wlr_scene_get_scene_output(output.server.scene, &output.wlr); + } + if (output.scene_output == nullptr || output.is_leased || !output.wlr.enabled) { return; } - wlr_scene* scene = output.server.scene; - wlr_scene_output* scene_output = wlr_scene_get_scene_output(scene, &output.wlr); - /* Render the scene if needed and commit the output */ - wlr_scene_output_commit(scene_output); + wlr_scene_output_commit(output.scene_output); - timespec now; + timespec now = {}; timespec_get(&now, TIME_UTC); - wlr_scene_output_send_frame_done(scene_output, &now); + wlr_scene_output_send_frame_done(output.scene_output, &now); } static void output_destroy_notify(wl_listener* listener, void* data) { @@ -52,7 +55,7 @@ static void output_destroy_notify(wl_listener* listener, void* data) { (void) data; output.server.outputs.erase(&output); - for (auto* layer : output.layers) { + for (const auto* layer : std::as_const(output.layers)) { wlr_layer_surface_v1_destroy(&layer->layer_surface); } @@ -62,7 +65,7 @@ static void output_destroy_notify(wl_listener* listener, void* data) { Output::Output(Server& server, wlr_output& wlr) noexcept : listeners(*this), server(server), wlr(wlr) { wlr.data = this; - is_leased = false; + scene_output = wlr_scene_get_scene_output(server.scene, &wlr); listeners.enable.notify = output_enable_notify; wl_signal_add(&wlr.events.enable, &listeners.enable); @@ -81,7 +84,7 @@ Output::~Output() noexcept { } void Output::update_layout() { - wlr_scene_output* scene_output = wlr_scene_get_scene_output(server.scene, &wlr); + const wlr_scene_output* scene_output = wlr_scene_get_scene_output(server.scene, &wlr); full_area.x = scene_output->x; full_area.y = scene_output->y; @@ -89,7 +92,7 @@ void Output::update_layout() { usable_area = full_area; - for (auto* layer : layers) { + for (const auto* layer : std::as_const(layers)) { wlr_scene_layer_surface_v1_configure(layer->scene_layer_surface, &full_area, &usable_area); } } @@ -99,8 +102,8 @@ wlr_box Output::full_area_in_layout_coords() const { wlr_output_layout_output_coords(server.output_layout, &wlr, &layout_x, &layout_y); wlr_box box = full_area; - box.x += layout_x; - box.y += layout_y; + box.x += static_cast(std::round(layout_x)); + box.y += static_cast(std::round(layout_y)); return box; } @@ -109,7 +112,7 @@ wlr_box Output::usable_area_in_layout_coords() const { wlr_output_layout_output_coords(server.output_layout, &wlr, &layout_x, &layout_y); wlr_box box = usable_area; - box.x += layout_x; - box.y += layout_y; + box.x += static_cast(std::round(layout_x)); + box.y += static_cast(std::round(layout_y)); return box; } diff --git a/src/output.hpp b/src/output.hpp index a90671ef5..9d18cc970 100644 --- a/src/output.hpp +++ b/src/output.hpp @@ -16,11 +16,11 @@ class Output { public: struct Listeners { std::reference_wrapper parent; - wl_listener enable; - wl_listener mode; - wl_listener frame; - wl_listener destroy; - Listeners(Output& parent) noexcept : parent(parent) {} + wl_listener enable = {}; + wl_listener mode = {}; + wl_listener frame = {}; + wl_listener destroy = {}; + explicit Listeners(Output& parent) noexcept : parent(parent) {} }; private: @@ -29,18 +29,18 @@ class Output { public: Server& server; wlr_output& wlr; - wlr_scene_output* scene_output; - wlr_box full_area; - wlr_box usable_area; + wlr_scene_output* scene_output = nullptr; + wlr_box full_area = {}; + wlr_box usable_area = {}; std::set layers; - bool is_leased; + bool is_leased = false; - Output(Server& server, wlr_output& output) noexcept; + Output(Server& server, wlr_output& wlr) noexcept; ~Output() noexcept; void update_layout(); - wlr_box full_area_in_layout_coords() const; - wlr_box usable_area_in_layout_coords() const; + [[nodiscard]] wlr_box full_area_in_layout_coords() const; + [[nodiscard]] wlr_box usable_area_in_layout_coords() const; }; #endif diff --git a/src/server.cpp b/src/server.cpp index f5caa0e66..710d3967a 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -10,7 +10,7 @@ #include "xwayland.hpp" #include -#include +#include #include "wlr-wrap-start.hpp" #include @@ -26,12 +26,13 @@ #include #include #include +#include #include #include #include "wlr-wrap-end.hpp" void Server::focus_view(View* view, wlr_surface* surface) { - wlr_surface* prev_surface = seat->wlr->keyboard_state.focused_surface; + const wlr_surface* prev_surface = seat->wlr->keyboard_state.focused_surface; if (prev_surface == surface && surface != nullptr) { /* Don't re-focus an already focused surface. */ return; @@ -41,7 +42,7 @@ void Server::focus_view(View* view, wlr_surface* surface) { wlr_surface* previous = seat->wlr->keyboard_state.focused_surface; if (wlr_surface_is_xdg_surface(previous)) { - wlr_xdg_surface* xdg_previous = wlr_xdg_surface_from_wlr_surface(previous); + const wlr_xdg_surface* xdg_previous = wlr_xdg_surface_from_wlr_surface(previous); assert(xdg_previous->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); wlr_xdg_toplevel_set_activated(xdg_previous->toplevel, false); } else if (wlr_surface_is_xwayland_surface(previous)) { @@ -52,15 +53,17 @@ void Server::focus_view(View* view, wlr_surface* surface) { if (view == nullptr) { return; - } else if (surface == nullptr) { + } + + if (surface == nullptr) { surface = view->get_wlr_surface(); } /* Move the view to the front */ wlr_scene_node_raise_to_top(view->scene_node); (void) std::remove(views.begin(), views.end(), view); - for (auto* view : views) { - view->set_activated(false); + for (auto* it : std::as_const(views)) { + it->set_activated(false); } /* Activate the new surface */ @@ -84,28 +87,33 @@ void Server::focus_view(View* view, wlr_surface* surface) { seat->set_constraint(constraint); } -Surface* Server::surface_at(const double lx, const double ly, wlr_surface** wlr, double* sx, double* sy) { +Surface* Server::surface_at(const double lx, const double ly, wlr_surface** wlr, double* sx, double* sy) const { /* This returns the topmost node in the scene at the given layout coords. * we only care about surface nodes as we are specifically looking for a * surface in the surface tree of a magpie_view. */ wlr_scene_node* node = wlr_scene_node_at(&scene->tree.node, lx, ly, sx, sy); - if (node == NULL || node->type != WLR_SCENE_NODE_BUFFER) { - return NULL; + if (node == nullptr || node->type != WLR_SCENE_NODE_BUFFER) { + return nullptr; } wlr_scene_buffer* scene_buffer = wlr_scene_buffer_from_node(node); - wlr_scene_surface* scene_surface = wlr_scene_surface_from_buffer(scene_buffer); + const wlr_scene_surface* scene_surface = wlr_scene_surface_from_buffer(scene_buffer); if (!scene_surface) { - return NULL; + return nullptr; } *wlr = scene_surface->surface; /* Find the node corresponding to the magpie_view at the root of this * surface tree, it is the only one for which we set the data field. */ - wlr_scene_tree* tree = node->parent; - while (tree != NULL && tree->node.data == NULL) { + const wlr_scene_tree* tree = node->parent; + while (tree != nullptr && tree->node.data == nullptr) { tree = tree->node.parent; } - return static_cast(tree->node.data); + + if (tree != nullptr) { + return static_cast(tree->node.data); + } + + return nullptr; } /* This event is raised by the backend when a new output (aka a display or @@ -137,7 +145,7 @@ static void new_output_notify(wl_listener* listener, void* data) { } /* Allocates and configures our state for this output */ - Output* output = new Output(server, *new_output); + auto* output = new Output(server, *new_output); server.outputs.emplace(output); /* Adds this to the output layout. The add_auto function arranges outputs @@ -156,7 +164,7 @@ static void new_output_notify(wl_listener* listener, void* data) { static void output_power_manager_set_mode_notify(wl_listener* listener, void* data) { (void) listener; - auto& event = *static_cast(data); + const auto& event = *static_cast(data); if (event.mode == ZWLR_OUTPUT_POWER_V1_MODE_ON) { wlr_output_enable(event.output, true); @@ -174,12 +182,12 @@ static void output_power_manager_set_mode_notify(wl_listener* listener, void* da * client, either a toplevel (application window) or popup. */ static void new_xdg_surface_notify(wl_listener* listener, void* data) { Server& server = magpie_container_of(listener, server, xdg_shell_new_xdg_surface); - auto& xdg_surface = *static_cast(data); + const auto& xdg_surface = *static_cast(data); if (xdg_surface.role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) { new XdgView(server, *xdg_surface.toplevel); } else if (xdg_surface.role == WLR_XDG_SURFACE_ROLE_POPUP) { - auto* surface = static_cast(xdg_surface.popup->parent->data); + const auto* surface = static_cast(xdg_surface.popup->parent->data); new Popup(*surface, *xdg_surface.popup); } } @@ -202,13 +210,13 @@ static void new_layer_surface_notify(wl_listener* listener, void* data) { static void request_activation_notify(wl_listener* listener, void* data) { Server& server = magpie_container_of(listener, server, activation_request_activation); - auto* event = static_cast(data); + const auto* event = static_cast(data); if (!wlr_surface_is_xdg_surface(event->surface)) { return; } - wlr_xdg_surface* xdg_surface = wlr_xdg_surface_from_wlr_surface(event->surface); + const wlr_xdg_surface* xdg_surface = wlr_xdg_surface_from_wlr_surface(event->surface); auto* view = dynamic_cast(static_cast(xdg_surface->surface->data)); if (view != nullptr && xdg_surface->mapped) { server.focus_view(view, xdg_surface->surface); @@ -219,7 +227,7 @@ static void drm_lease_notify(wl_listener* listener, void* data) { Server& server = magpie_container_of(listener, server, drm_lease_request); auto* request = static_cast(data); - wlr_drm_lease_v1* lease = wlr_drm_lease_request_v1_grant(request); + const wlr_drm_lease_v1* lease = wlr_drm_lease_request_v1_grant(request); if (lease == nullptr) { wlr_drm_lease_request_v1_reject(request); return; @@ -248,10 +256,10 @@ void output_layout_change_notify(wl_listener* listener, void* data) { wlr_output_configuration_v1* config = wlr_output_configuration_v1_create(); - for (auto* output : server.outputs) { + for (const auto* output : std::as_const(server.outputs)) { wlr_output_configuration_head_v1* head = wlr_output_configuration_head_v1_create(config, &output->wlr); - wlr_box box; + wlr_box box = {}; wlr_output_layout_get_box(server.output_layout, &output->wlr, &box); if (!wlr_box_empty(&box)) { head->state.x = box.x; @@ -271,18 +279,18 @@ void output_manager_apply_notify(wl_listener* listener, void* data) { wlr_output_configuration_head_v1* head; wl_list_for_each(head, &config.heads, link) { Output& output = *static_cast(head->state.output->data); - bool enabled = head->state.enabled && !output.is_leased; - bool adding = enabled && !output.wlr.enabled; - bool removing = !enabled && output.wlr.enabled; + const bool enabled = head->state.enabled && !output.is_leased; + const bool adding = enabled && !output.wlr.enabled; + const bool removing = !enabled && output.wlr.enabled; wlr_output_enable(&output.wlr, enabled); if (enabled) { if (head->state.mode) { wlr_output_set_mode(&output.wlr, head->state.mode); } else { - int32_t width = head->state.custom_mode.width; - int32_t height = head->state.custom_mode.height; - int32_t refresh = head->state.custom_mode.refresh; + const int32_t width = head->state.custom_mode.width; + const int32_t height = head->state.custom_mode.height; + const int32_t refresh = head->state.custom_mode.refresh; wlr_output_set_custom_mode(&output.wlr, width, height, refresh); } @@ -301,7 +309,7 @@ void output_manager_apply_notify(wl_listener* listener, void* data) { } if (enabled) { - wlr_box box; + wlr_box box = {}; wlr_output_layout_get_box(server.output_layout, &output.wlr, &box); if (box.x != head->state.x || box.y != head->state.y) { /* This overrides the automatic layout */ diff --git a/src/server.hpp b/src/server.hpp index 20a24ce72..a812eafbb 100644 --- a/src/server.hpp +++ b/src/server.hpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include "wlr-wrap-end.hpp" @@ -35,15 +34,15 @@ class Server { public: struct Listeners { std::reference_wrapper parent; - wl_listener xdg_shell_new_xdg_surface; - wl_listener layer_shell_new_layer_surface; - wl_listener activation_request_activation; - wl_listener backend_new_output; - wl_listener drm_lease_request; - wl_listener output_layout_change; - wl_listener output_manager_apply; - wl_listener output_power_manager_set_mode; - Listeners(Server& parent) noexcept : parent(parent) {} + wl_listener xdg_shell_new_xdg_surface = {}; + wl_listener layer_shell_new_layer_surface = {}; + wl_listener activation_request_activation = {}; + wl_listener backend_new_output = {}; + wl_listener drm_lease_request = {}; + wl_listener output_layout_change = {}; + wl_listener output_manager_apply = {}; + wl_listener output_power_manager_set_mode = {}; + explicit Listeners(Server& parent) noexcept : parent(parent) {} }; private: @@ -59,7 +58,7 @@ class Server { XWayland* xwayland; wlr_scene* scene; - wlr_scene_tree* scene_layers[MAGPIE_SCENE_LAYER_LOCK + 1]; + wlr_scene_tree* scene_layers[MAGPIE_SCENE_LAYER_LOCK + 1] = {}; wlr_xdg_shell* xdg_shell; @@ -74,9 +73,9 @@ class Server { std::list views; View* focused_view = nullptr; View* grabbed_view = nullptr; - double grab_x, grab_y; - wlr_box grab_geobox; - uint32_t resize_edges; + double grab_x = 0.0, grab_y = 0.0; + wlr_box grab_geobox = {}; + uint32_t resize_edges = 0; wlr_output_manager_v1* output_manager; wlr_output_power_manager_v1* output_power_manager; @@ -91,7 +90,7 @@ class Server { Server(); - Surface* surface_at(const double lx, const double ly, wlr_surface** wlr, double* sx, double* sy); + Surface* surface_at(double lx, double ly, wlr_surface** wlr, double* sx, double* sy) const; void focus_view(View* view, wlr_surface* surface = nullptr); }; diff --git a/src/surface/layer.cpp b/src/surface/layer.cpp index b7d7cc3b8..0c9e6dcf4 100644 --- a/src/surface/layer.cpp +++ b/src/surface/layer.cpp @@ -15,7 +15,7 @@ #include #include "wlr-wrap-end.hpp" -static magpie_scene_layer_t magpie_layer_from_wlr_layer(enum zwlr_layer_shell_v1_layer layer) { +static magpie_scene_layer_t magpie_layer_from_wlr_layer(const zwlr_layer_shell_v1_layer layer) { switch (layer) { case ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND: return MAGPIE_SCENE_LAYER_BACKGROUND; @@ -75,12 +75,12 @@ static void wlr_layer_surface_v1_commit_notify(wl_listener* listener, void* data Layer& layer = magpie_container_of(listener, layer, commit); (void) data; - Server& server = layer.output.server; - wlr_layer_surface_v1& surface = layer.layer_surface; + const Server& server = layer.output.server; + const wlr_layer_surface_v1& surface = layer.layer_surface; - uint32_t committed = surface.current.committed; + const uint32_t committed = surface.current.committed; if (committed & WLR_LAYER_SURFACE_V1_STATE_LAYER) { - magpie_scene_layer_t chosen_layer = magpie_layer_from_wlr_layer(surface.current.layer); + const magpie_scene_layer_t chosen_layer = magpie_layer_from_wlr_layer(surface.current.layer); wlr_scene_node_reparent(layer.scene_node, server.scene_layers[chosen_layer]); } @@ -91,7 +91,7 @@ static void wlr_layer_surface_v1_commit_notify(wl_listener* listener, void* data static void wlr_layer_surface_v1_new_popup_notify(wl_listener* listener, void* data) { Layer& layer = magpie_container_of(listener, layer, new_popup); - auto* surface = static_cast(layer.layer_surface.surface->data); + const auto* surface = static_cast(layer.layer_surface.surface->data); new Popup(*surface, *static_cast(data)); } @@ -105,7 +105,7 @@ static void wlr_layer_surface_v1_new_subsurface_notify(wl_listener* listener, vo Layer::Layer(Output& output, wlr_layer_surface_v1& surface) noexcept : listeners(*this), server(output.server), output(output), layer_surface(surface) { - magpie_scene_layer_t chosen_layer = magpie_layer_from_wlr_layer(surface.current.layer); + const magpie_scene_layer_t chosen_layer = magpie_layer_from_wlr_layer(surface.current.layer); scene_layer_surface = wlr_scene_layer_surface_v1_create(output.server.scene_layers[chosen_layer], &surface); scene_node = &scene_layer_surface->tree->node; diff --git a/src/surface/layer.hpp b/src/surface/layer.hpp index a7cdf2c58..6647781df 100644 --- a/src/surface/layer.hpp +++ b/src/surface/layer.hpp @@ -9,17 +9,17 @@ #include #include "wlr-wrap-end.hpp" -class Layer : public Surface { +class Layer final : public Surface { public: struct Listeners { std::reference_wrapper parent; - wl_listener map; - wl_listener unmap; - wl_listener destroy; - wl_listener commit; - wl_listener new_popup; - wl_listener new_subsurface; - Listeners(Layer& parent) noexcept : parent(parent) {} + wl_listener map = {}; + wl_listener unmap = {}; + wl_listener destroy = {}; + wl_listener commit = {}; + wl_listener new_popup = {}; + wl_listener new_subsurface = {}; + explicit Listeners(Layer& parent) noexcept : parent(parent) {} }; private: @@ -35,22 +35,22 @@ class Layer : public Surface { std::set subsurfaces; Layer(Output& output, wlr_layer_surface_v1& surface) noexcept; - ~Layer() noexcept; + ~Layer() noexcept override; - constexpr wlr_surface* get_wlr_surface() const override; - constexpr Server& get_server() const override; - constexpr bool is_view() const override; + [[nodiscard]] constexpr wlr_surface* get_wlr_surface() const override; + [[nodiscard]] constexpr Server& get_server() const override; + [[nodiscard]] constexpr bool is_view() const override; }; class LayerSubsurface { public: struct Listeners { std::reference_wrapper parent; - wl_listener map; - wl_listener unmap; - wl_listener destroy; - wl_listener commit; - Listeners(LayerSubsurface& parent) noexcept : parent(parent) {} + wl_listener map = {}; + wl_listener unmap = {}; + wl_listener destroy = {}; + wl_listener commit = {}; + explicit Listeners(LayerSubsurface& parent) noexcept : parent(parent) {} }; private: @@ -60,7 +60,7 @@ class LayerSubsurface { Layer& parent; wlr_subsurface& subsurface; - LayerSubsurface(Layer& parent_layer, wlr_subsurface& subsurface) noexcept; + LayerSubsurface(Layer& parent, wlr_subsurface& subsurface) noexcept; ~LayerSubsurface() noexcept; }; diff --git a/src/surface/popup.hpp b/src/surface/popup.hpp index 201744998..d89dc401e 100644 --- a/src/surface/popup.hpp +++ b/src/surface/popup.hpp @@ -8,16 +8,16 @@ #include #include "wlr-wrap-end.hpp" -class Popup : public Surface { +class Popup final : public Surface { public: struct Listeners { std::reference_wrapper parent; - wl_listener map; - wl_listener unmap; - wl_listener destroy; - wl_listener commit; - wl_listener new_popup; - Listeners(Popup& parent) noexcept : parent(parent) {} + wl_listener map = {}; + wl_listener unmap = {}; + wl_listener destroy = {}; + wl_listener commit = {}; + wl_listener new_popup = {}; + explicit Listeners(Popup& parent) noexcept : parent(parent) {} }; private: @@ -28,12 +28,12 @@ class Popup : public Surface { const Surface& parent; wlr_xdg_popup& wlr; - Popup(const Surface& parent, wlr_xdg_popup& xdg_popup) noexcept; - ~Popup() noexcept; + Popup(const Surface& parent, wlr_xdg_popup& wlr) noexcept; + ~Popup() noexcept override; - constexpr wlr_surface* get_wlr_surface() const override; - constexpr Server& get_server() const override; - constexpr bool is_view() const override; + [[nodiscard]] constexpr wlr_surface* get_wlr_surface() const override; + [[nodiscard]] constexpr Server& get_server() const override; + [[nodiscard]] constexpr bool is_view() const override; }; #endif diff --git a/src/surface/surface.hpp b/src/surface/surface.hpp index 04228a8bb..d06b9b752 100644 --- a/src/surface/surface.hpp +++ b/src/surface/surface.hpp @@ -14,11 +14,11 @@ enum SurfaceType { MAGPIE_SURFACE_TYPE_VIEW, MAGPIE_SURFACE_TYPE_LAYER, MAGPIE_S struct Surface { wlr_scene_node* scene_node = nullptr; - virtual ~Surface() noexcept {}; + virtual ~Surface() noexcept = default; - virtual constexpr Server& get_server() const = 0; - virtual constexpr wlr_surface* get_wlr_surface() const = 0; - virtual constexpr bool is_view() const = 0; + [[nodiscard]] virtual constexpr Server& get_server() const = 0; + [[nodiscard]] virtual constexpr wlr_surface* get_wlr_surface() const = 0; + [[nodiscard]] virtual constexpr bool is_view() const = 0; }; #endif diff --git a/src/surface/view.cpp b/src/surface/view.cpp index 164d14970..f5e5ea11a 100644 --- a/src/surface/view.cpp +++ b/src/surface/view.cpp @@ -4,8 +4,8 @@ #include "input/seat.hpp" #include "output.hpp" #include "server.hpp" - #include "types.hpp" + #include "wlr-wrap-start.hpp" #include #include @@ -13,30 +13,29 @@ #include #include #include -#include #include "wlr-wrap-end.hpp" -const std::optional View::find_output_for_maximize() { - Server& server = get_server(); +std::optional View::find_output_for_maximize() const { + const Server& server = get_server(); if (server.outputs.empty()) { return {}; } - Cursor& cursor = server.seat->cursor; + const Cursor& cursor = server.seat->cursor; Output* best_output = nullptr; - long best_area = 0; + int64_t best_area = 0; for (auto* output : server.outputs) { if (!wlr_output_layout_intersects(server.output_layout, &output->wlr, &previous)) { continue; } - wlr_box output_box; + wlr_box output_box = {}; wlr_output_layout_get_box(server.output_layout, &output->wlr, &output_box); - wlr_box intersection; + wlr_box intersection = {}; wlr_box_intersection(&intersection, &previous, &output_box); - long intersection_area = intersection.width * intersection.height; + const int64_t intersection_area = intersection.width * intersection.height; if (intersection.width * intersection.height > best_area) { best_area = intersection_area; @@ -47,7 +46,9 @@ const std::optional View::find_output_for_maximize() { // if it's outside of all outputs, just use the pointer position if (best_output == nullptr) { for (auto* output : server.outputs) { - if (wlr_output_layout_contains_point(server.output_layout, &output->wlr, cursor.wlr.x, cursor.wlr.y)) { + const auto cx = static_cast(std::round(cursor.wlr.x)); + const auto cy = static_cast(std::round(cursor.wlr.y)); + if (wlr_output_layout_contains_point(server.output_layout, &output->wlr, cx, cy)) { best_output = output; break; } @@ -80,10 +81,10 @@ void View::begin_interactive(const CursorMode mode, const uint32_t edges) { server.grab_x = cursor.wlr.x - current.x; server.grab_y = cursor.wlr.y - current.y; } else { - wlr_box geo_box = get_geometry(); + const wlr_box geo_box = get_geometry(); - double border_x = (current.x + geo_box.x) + ((edges & WLR_EDGE_RIGHT) ? geo_box.width : 0); - double border_y = (current.y + geo_box.y) + ((edges & WLR_EDGE_BOTTOM) ? geo_box.height : 0); + const double border_x = current.x + geo_box.x + (edges & WLR_EDGE_RIGHT ? geo_box.width : 0); + const double border_y = current.y + geo_box.y + (edges & WLR_EDGE_BOTTOM ? geo_box.height : 0); server.grab_x = cursor.wlr.x - border_x; server.grab_y = cursor.wlr.y - border_y; @@ -125,7 +126,7 @@ void View::set_activated(const bool activated) { } void View::set_placement(const ViewPlacement new_placement, const bool force) { - Server& server = get_server(); + const Server& server = get_server(); if (!force) { if (curr_placement == new_placement) { @@ -170,12 +171,12 @@ void View::stack() { } bool View::maximize() { - auto best_output = find_output_for_maximize(); + const auto best_output = find_output_for_maximize(); if (!best_output.has_value()) { return false; } - wlr_box output_box = best_output.value()->usable_area_in_layout_coords(); + const wlr_box output_box = best_output.value()->usable_area_in_layout_coords(); set_size(output_box.width, output_box.height); impl_set_fullscreen(false); impl_set_maximized(true); @@ -185,12 +186,12 @@ bool View::maximize() { } bool View::fullscreen() { - auto best_output = find_output_for_maximize(); + const auto best_output = find_output_for_maximize(); if (!best_output.has_value()) { return false; } - wlr_box output_box = best_output.value()->full_area_in_layout_coords(); + const wlr_box output_box = best_output.value()->full_area_in_layout_coords(); set_size(output_box.width, output_box.height); impl_set_fullscreen(true); set_position(output_box.x, output_box.y); diff --git a/src/surface/view.hpp b/src/surface/view.hpp index dea9f5e7c..366fccff9 100644 --- a/src/surface/view.hpp +++ b/src/surface/view.hpp @@ -14,7 +14,7 @@ #include #include "wlr-wrap-end.hpp" -struct View : public Surface { +struct View : Surface { ViewPlacement prev_placement = VIEW_PLACEMENT_STACKING; ViewPlacement curr_placement = VIEW_PLACEMENT_STACKING; bool is_minimized = false; @@ -23,56 +23,56 @@ struct View : public Surface { wlr_box previous; std::optional toplevel_handle = {}; - virtual ~View() noexcept {}; + ~View() noexcept override = default; - virtual const wlr_box get_geometry() const = 0; + [[nodiscard]] virtual wlr_box get_geometry() const = 0; virtual void map() = 0; virtual void unmap() = 0; - constexpr bool is_view() const override { + [[nodiscard]] constexpr bool is_view() const override { return true; } - void begin_interactive(const CursorMode mode, const uint32_t edges); - void set_position(const int new_x, const int new_y); - void set_size(const int new_width, const int new_height); - void set_activated(const bool activated); - void set_placement(const ViewPlacement placement, const bool force = false); - void set_minimized(const bool minimized); + void begin_interactive(CursorMode mode, uint32_t edges); + void set_position(int new_x, int new_y); + void set_size(int new_width, int new_height); + void set_activated(bool activated); + void set_placement(ViewPlacement new_placement, bool force = false); + void set_minimized(bool minimized); void toggle_maximize(); void toggle_fullscreen(); private: - const std::optional find_output_for_maximize(); + [[nodiscard]] std::optional find_output_for_maximize() const; void stack(); bool maximize(); bool fullscreen(); protected: - virtual void impl_set_position(const int new_x, const int new_y) = 0; - 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_fullscreen(const bool fullscreen) = 0; - virtual void impl_set_maximized(const bool maximized) = 0; - virtual void impl_set_minimized(const bool minimized) = 0; + virtual void impl_set_position(int new_x, int new_y) = 0; + virtual void impl_set_size(int new_width, int new_height) = 0; + virtual void impl_set_activated(bool activated) = 0; + virtual void impl_set_fullscreen(bool fullscreen) = 0; + virtual void impl_set_maximized(bool maximized) = 0; + virtual void impl_set_minimized(bool minimized) = 0; }; -class XdgView : public View { +class XdgView final : public View { public: struct Listeners { std::reference_wrapper parent; - wl_listener map; - wl_listener unmap; - wl_listener destroy; - wl_listener commit; - wl_listener request_move; - wl_listener request_resize; - wl_listener request_maximize; - wl_listener request_minimize; - wl_listener request_fullscreen; - wl_listener set_title; - wl_listener set_app_id; - wl_listener set_parent; - Listeners(XdgView& parent) noexcept : parent(parent) {} + wl_listener map = {}; + wl_listener unmap = {}; + wl_listener destroy = {}; + wl_listener commit = {}; + wl_listener request_move = {}; + wl_listener request_resize = {}; + wl_listener request_maximize = {}; + wl_listener request_minimize = {}; + wl_listener request_fullscreen = {}; + wl_listener set_title = {}; + wl_listener set_app_id = {}; + wl_listener set_parent = {}; + explicit Listeners(XdgView& parent) noexcept : parent(parent) {} }; private: @@ -84,11 +84,11 @@ class XdgView : public View { wlr_xdg_toplevel& xdg_toplevel; XdgView(Server& server, wlr_xdg_toplevel& toplevel) noexcept; - ~XdgView() noexcept; + ~XdgView() noexcept override; - constexpr wlr_surface* get_wlr_surface() const override; - constexpr Server& get_server() const override; - const wlr_box get_geometry() const override; + [[nodiscard]] constexpr wlr_surface* get_wlr_surface() const override; + [[nodiscard]] constexpr Server& get_server() const override; + [[nodiscard]] wlr_box get_geometry() const override; void map() override; void unmap() override; @@ -101,24 +101,24 @@ class XdgView : public View { void impl_set_minimized(bool minimized) override; }; -class XWaylandView : public View { +class XWaylandView final : public View { public: struct Listeners { std::reference_wrapper parent; - wl_listener map; - wl_listener unmap; - wl_listener destroy; - wl_listener commit; - wl_listener request_configure; - wl_listener request_move; - wl_listener request_resize; - wl_listener request_maximize; - wl_listener request_fullscreen; - wl_listener set_geometry; - wl_listener set_title; - wl_listener set_class; - wl_listener set_parent; - Listeners(XWaylandView& parent) noexcept : parent(parent) {} + wl_listener map = {}; + wl_listener unmap = {}; + wl_listener destroy = {}; + wl_listener commit = {}; + wl_listener request_configure = {}; + wl_listener request_move = {}; + wl_listener request_resize = {}; + wl_listener request_maximize = {}; + wl_listener request_fullscreen = {}; + wl_listener set_geometry = {}; + wl_listener set_title = {}; + wl_listener set_class = {}; + wl_listener set_parent = {}; + explicit Listeners(XWaylandView& parent) noexcept : parent(parent) {} }; private: @@ -129,11 +129,11 @@ class XWaylandView : public View { wlr_xwayland_surface& xwayland_surface; XWaylandView(Server& server, wlr_xwayland_surface& surface) noexcept; - ~XWaylandView() noexcept; + ~XWaylandView() noexcept override; - constexpr wlr_surface* get_wlr_surface() const override; - constexpr Server& get_server() const override; - const wlr_box get_geometry() const override; + [[nodiscard]] constexpr wlr_surface* get_wlr_surface() const override; + [[nodiscard]] constexpr Server& get_server() const override; + [[nodiscard]] constexpr wlr_box get_geometry() const override; void map() override; void unmap() override; diff --git a/src/surface/xdg_view.cpp b/src/surface/xdg_view.cpp index e370cc116..85e76c2eb 100644 --- a/src/surface/xdg_view.cpp +++ b/src/surface/xdg_view.cpp @@ -10,8 +10,6 @@ #include "wlr-wrap-start.hpp" #include #include -#include -#include #include "wlr-wrap-end.hpp" /* Called when the surface is mapped, or ready to display on-screen. */ @@ -59,7 +57,7 @@ static void xdg_toplevel_request_move_notify(wl_listener* listener, void* data) * client, to prevent the client from requesting this whenever they want. */ static void xdg_toplevel_request_resize_notify(wl_listener* listener, void* data) { XdgView& view = magpie_container_of(listener, view, request_resize); - auto* event = static_cast(data); + const auto* event = static_cast(data); view.set_placement(VIEW_PLACEMENT_STACKING); view.begin_interactive(MAGPIE_CURSOR_RESIZE, event->edges); @@ -111,7 +109,7 @@ static void xdg_toplevel_set_parent_notify(wl_listener* listener, void* data) { (void) data; if (view.xdg_toplevel.parent != nullptr) { - auto* m_view = dynamic_cast(static_cast(view.xdg_toplevel.parent->base->data)); + const auto* m_view = dynamic_cast(static_cast(view.xdg_toplevel.parent->base->data)); if (m_view != nullptr) { view.toplevel_handle->set_parent(m_view->toplevel_handle); return; @@ -192,8 +190,8 @@ constexpr Server& XdgView::get_server() const { return server; } -const wlr_box XdgView::get_geometry() const { - wlr_box box; +wlr_box XdgView::get_geometry() const { + wlr_box box = {}; wlr_xdg_surface_get_geometry(xdg_toplevel.base, &box); return box; } @@ -204,11 +202,11 @@ void XdgView::map() { wlr_xdg_surface_get_geometry(xdg_toplevel.base, ¤t); if (!server.outputs.empty()) { - auto output = static_cast(wlr_output_layout_get_center_output(server.output_layout)->data); - auto usable_area = output->usable_area_in_layout_coords(); - auto center_x = usable_area.x + (usable_area.width / 2); - auto center_y = usable_area.y + (usable_area.height / 2); - set_position(center_x - (current.width / 2), center_y - (current.height / 2)); + const auto output = static_cast(wlr_output_layout_get_center_output(server.output_layout)->data); + const auto usable_area = output->usable_area_in_layout_coords(); + const auto center_x = usable_area.x + usable_area.width / 2; + const auto center_y = usable_area.y + usable_area.height / 2; + set_position(center_x - current.width / 2, center_y - current.height / 2); } pending_map = false; diff --git a/src/surface/xwayland_view.cpp b/src/surface/xwayland_view.cpp index a8614c450..47d9d2aae 100644 --- a/src/surface/xwayland_view.cpp +++ b/src/surface/xwayland_view.cpp @@ -10,10 +10,7 @@ #include #include "wlr-wrap-start.hpp" -#include -#include #include -#include #include "wlr-wrap-end.hpp" /* Called when the surface is mapped, or ready to display on-screen. */ @@ -45,7 +42,7 @@ static void xwayland_surface_request_configure_notify(wl_listener* listener, voi XWaylandView& view = magpie_container_of(listener, view, request_configure); wlr_xwayland_surface& surface = view.xwayland_surface; - auto* event = static_cast(data); + const auto* event = static_cast(data); wlr_xwayland_surface_configure(&surface, event->x, event->y, event->width, event->height); view.current = {event->x, event->y, event->width, event->height}; @@ -59,7 +56,7 @@ static void xwayland_surface_set_geometry_notify(wl_listener* listener, void* da XWaylandView& view = magpie_container_of(listener, view, set_geometry); (void) data; - wlr_xwayland_surface& surface = view.xwayland_surface; + const wlr_xwayland_surface& surface = view.xwayland_surface; view.current = {surface.x, surface.y, surface.width, surface.height}; if (surface.mapped) { @@ -87,7 +84,7 @@ static void xwayland_surface_request_move_notify(wl_listener* listener, void* da * client, to prevent the client from requesting this whenever they want. */ static void xwayland_surface_request_resize_notify(wl_listener* listener, void* data) { XWaylandView& view = magpie_container_of(listener, view, request_resize); - auto* event = static_cast(data); + const auto* event = static_cast(data); view.set_placement(VIEW_PLACEMENT_STACKING); view.begin_interactive(MAGPIE_CURSOR_RESIZE, event->edges); @@ -145,35 +142,35 @@ static void xwayland_surface_set_parent_notify(wl_listener* listener, void* data } } -XWaylandView::XWaylandView(Server& server, wlr_xwayland_surface& xwayland_surface) noexcept - : listeners(*this), server(server), xwayland_surface(xwayland_surface) { - this->xwayland_surface = xwayland_surface; +XWaylandView::XWaylandView(Server& server, wlr_xwayland_surface& surface) noexcept + : listeners(*this), server(server), xwayland_surface(surface) { + this->xwayland_surface = surface; /* Listen to the various events it can emit */ listeners.map.notify = xwayland_surface_map_notify; - wl_signal_add(&xwayland_surface.events.map, &listeners.map); + wl_signal_add(&surface.events.map, &listeners.map); listeners.unmap.notify = xwayland_surface_unmap_notify; - wl_signal_add(&xwayland_surface.events.unmap, &listeners.unmap); + wl_signal_add(&surface.events.unmap, &listeners.unmap); listeners.destroy.notify = xwayland_surface_destroy_notify; - wl_signal_add(&xwayland_surface.events.destroy, &listeners.destroy); + wl_signal_add(&surface.events.destroy, &listeners.destroy); listeners.request_configure.notify = xwayland_surface_request_configure_notify; - wl_signal_add(&xwayland_surface.events.request_configure, &listeners.request_configure); + wl_signal_add(&surface.events.request_configure, &listeners.request_configure); listeners.request_move.notify = xwayland_surface_request_move_notify; - wl_signal_add(&xwayland_surface.events.request_move, &listeners.request_move); + wl_signal_add(&surface.events.request_move, &listeners.request_move); listeners.request_resize.notify = xwayland_surface_request_resize_notify; - wl_signal_add(&xwayland_surface.events.request_resize, &listeners.request_resize); + wl_signal_add(&surface.events.request_resize, &listeners.request_resize); listeners.request_maximize.notify = xwayland_surface_request_maximize_notify; - wl_signal_add(&xwayland_surface.events.request_maximize, &listeners.request_maximize); + wl_signal_add(&surface.events.request_maximize, &listeners.request_maximize); listeners.request_fullscreen.notify = xwayland_surface_request_fullscreen_notify; - wl_signal_add(&xwayland_surface.events.request_fullscreen, &listeners.request_fullscreen); + wl_signal_add(&surface.events.request_fullscreen, &listeners.request_fullscreen); listeners.set_geometry.notify = xwayland_surface_set_geometry_notify; - wl_signal_add(&xwayland_surface.events.set_geometry, &listeners.set_geometry); + wl_signal_add(&surface.events.set_geometry, &listeners.set_geometry); listeners.set_title.notify = xwayland_surface_set_title_notify; - wl_signal_add(&xwayland_surface.events.set_title, &listeners.set_title); + wl_signal_add(&surface.events.set_title, &listeners.set_title); listeners.set_class.notify = xwayland_surface_set_class_notify; - wl_signal_add(&xwayland_surface.events.set_class, &listeners.set_class); + wl_signal_add(&surface.events.set_class, &listeners.set_class); listeners.set_parent.notify = xwayland_surface_set_parent_notify; - wl_signal_add(&xwayland_surface.events.set_parent, &listeners.set_parent); + wl_signal_add(&surface.events.set_parent, &listeners.set_parent); } XWaylandView::~XWaylandView() noexcept { @@ -197,13 +194,8 @@ constexpr Server& XWaylandView::get_server() const { return server; } -const wlr_box XWaylandView::get_geometry() const { - wlr_box box; - box.x = xwayland_surface.x; - box.y = xwayland_surface.y; - box.width = xwayland_surface.width; - box.height = xwayland_surface.height; - return box; +constexpr wlr_box XWaylandView::get_geometry() const { + return {xwayland_surface.x, xwayland_surface.y, xwayland_surface.width, xwayland_surface.height}; } void XWaylandView::map() { @@ -219,7 +211,7 @@ void XWaylandView::map() { scene_node->data = this; if (xwayland_surface.parent != nullptr) { - auto* m_view = dynamic_cast(static_cast(xwayland_surface.parent->data)); + const auto* m_view = dynamic_cast(static_cast(xwayland_surface.parent->data)); if (m_view != nullptr) { wlr_scene_node_reparent(scene_node, m_view->scene_node->parent); toplevel_handle->set_parent(m_view->toplevel_handle); @@ -253,7 +245,7 @@ void XWaylandView::unmap() { } if (server.seat->wlr->keyboard_state.focused_surface == xwayland_surface.surface) { - server.seat->wlr->keyboard_state.focused_surface = NULL; + server.seat->wlr->keyboard_state.focused_surface = nullptr; } wlr_scene_node_destroy(scene_node); @@ -262,18 +254,30 @@ void XWaylandView::unmap() { toplevel_handle.reset(); } +static constexpr int16_t trunc(const int32_t int32) { + if (int32 > INT16_MAX) { + return INT16_MAX; + } + + if (int32 < INT16_MIN) { + return INT16_MIN; + } + + return static_cast(int32); +} + void XWaylandView::impl_set_position(const int new_x, const int new_y) { - wlr_xwayland_surface_configure(&xwayland_surface, new_x, new_y, current.width, current.height); + wlr_xwayland_surface_configure(&xwayland_surface, trunc(new_x), trunc(new_y), current.width, current.height); } void XWaylandView::impl_set_size(const int new_width, const int new_height) { - wlr_xwayland_surface_configure(&xwayland_surface, current.x, current.y, new_width, new_height); + wlr_xwayland_surface_configure(&xwayland_surface, trunc(current.x), trunc(current.y), new_width, new_height); } -void XWaylandView::impl_set_activated(bool activated) { +void XWaylandView::impl_set_activated(const bool activated) { wlr_xwayland_surface_activate(&xwayland_surface, activated); if (activated) { - wlr_xwayland_surface_restack(&xwayland_surface, NULL, XCB_STACK_MODE_ABOVE); + wlr_xwayland_surface_restack(&xwayland_surface, nullptr, XCB_STACK_MODE_ABOVE); } } diff --git a/src/xwayland.cpp b/src/xwayland.cpp index 458005acd..7670a943c 100644 --- a/src/xwayland.cpp +++ b/src/xwayland.cpp @@ -1,5 +1,3 @@ -#define _POSIX_C_SOURCE 200809L - #include "xwayland.hpp" #include "input/seat.hpp" @@ -31,9 +29,8 @@ static void ready_notify(wl_listener* listener, void* data) { wlr_xwayland_set_seat(xwayland.wlr, xwayland.server.seat->wlr); - xcb_connection_t* xcb_conn = xcb_connect(NULL, NULL); - int err = xcb_connection_has_error(xcb_conn); - if (err) { + xcb_connection_t* xcb_conn = xcb_connect(nullptr, nullptr); + if (const int err = xcb_connection_has_error(xcb_conn)) { wlr_log(WLR_ERROR, "XCB connect failed: %d", err); return; } @@ -43,14 +40,14 @@ static void ready_notify(wl_listener* listener, void* data) { cookies[i] = xcb_intern_atom(xcb_conn, 0, strlen(atom_map[i]), atom_map[i]); } for (size_t i = 0; i < ATOM_LAST; i++) { - xcb_generic_error_t* error = NULL; + xcb_generic_error_t* error = nullptr; xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(xcb_conn, cookies[i], &error); - if (reply != NULL && error == NULL) { + if (reply != nullptr && error == nullptr) { xwayland.atoms[i] = reply->atom; } free(reply); - if (error != NULL) { + if (error != nullptr) { wlr_log(WLR_ERROR, "could not resolve atom %s: X11 error code %d", atom_map[i], error->error_code); free(error); break; diff --git a/src/xwayland.hpp b/src/xwayland.hpp index 764e6da61..3faa87b7d 100644 --- a/src/xwayland.hpp +++ b/src/xwayland.hpp @@ -1,5 +1,5 @@ -#ifndef MAGPIE_XWAYLAND_H -#define MAGPIE_XWAYLAND_H +#ifndef MAGPIE_XWAYLAND_HPP +#define MAGPIE_XWAYLAND_HPP #include "types.hpp" @@ -29,9 +29,9 @@ class XWayland { public: struct Listeners { std::reference_wrapper parent; - wl_listener ready; - wl_listener new_surface; - Listeners(XWayland& parent) noexcept : parent(parent) {} + wl_listener ready = {}; + wl_listener new_surface = {}; + explicit Listeners(XWayland& parent) noexcept : parent(parent) {} }; private: @@ -40,9 +40,9 @@ class XWayland { public: Server& server; wlr_xwayland* wlr; - xcb_atom_t atoms[ATOM_LAST]; + xcb_atom_t atoms[ATOM_LAST] = {}; - XWayland(Server& server) noexcept; + explicit XWayland(Server& server) noexcept; }; #endif