Skip to content

Commit

Permalink
General code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
serebit committed Nov 26, 2023
1 parent 8bbd05c commit e106dfe
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments:
Enabled: false
AlignOperands: true
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
Expand Down
6 changes: 2 additions & 4 deletions src/foreign_toplevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ static void foreign_toplevel_handle_request_minimize_notify(wl_listener* listene
handle.view.set_minimized(event.minimized);
}

static void foreign_toplevel_handle_request_activate_notify(wl_listener* listener, void* data) {
static void foreign_toplevel_handle_request_activate_notify(wl_listener* listener, void*) {
const ForeignToplevelHandle& handle = magpie_container_of(listener, handle, request_activate);
(void) data;

handle.view.set_minimized(false);
handle.view.get_server().focus_view(&handle.view);
}

static void foreign_toplevel_handle_request_close_notify(wl_listener* listener, void* data) {
static void foreign_toplevel_handle_request_close_notify(wl_listener* listener, void*) {
const ForeignToplevelHandle& handle = magpie_container_of(listener, handle, request_close);
(void) data;

handle.view.close();
}
Expand Down
19 changes: 1 addition & 18 deletions src/input/constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,8 @@
#include <wlr/types/wlr_compositor.h>
#include "wlr-wrap-end.hpp"

static void constraint_set_region_notify(wl_listener* listener, void* data) {
(void) listener;
(void) data;
}

static void constraint_surface_commit_notify(wl_listener* listener, void* data) {
(void) listener;
(void) data;
}

static void constraint_destroy_notify(wl_listener* listener, void* data) {
static void constraint_destroy_notify(wl_listener* listener, void*) {
PointerConstraint& constraint = magpie_container_of(listener, constraint, destroy);
(void) data;

auto& current_constraint = constraint.seat.current_constraint;
if (current_constraint.has_value() && &current_constraint.value().get().wlr == &constraint.wlr) {
Expand All @@ -35,17 +24,11 @@ static void constraint_destroy_notify(wl_listener* listener, void* data) {

PointerConstraint::PointerConstraint(Seat& seat, wlr_pointer_constraint_v1& wlr) noexcept
: listeners(*this), seat(seat), wlr(wlr) {
listeners.set_region.notify = constraint_set_region_notify;
wl_signal_add(&wlr.events.set_region, &listeners.set_region);
listeners.surface_commit.notify = constraint_surface_commit_notify;
wl_signal_add(&wlr.surface->events.commit, &listeners.surface_commit);
listeners.destroy.notify = constraint_destroy_notify;
wl_signal_add(&wlr.events.destroy, &listeners.destroy);
}

PointerConstraint::~PointerConstraint() noexcept {
wl_list_remove(&listeners.set_region.link);
wl_list_remove(&listeners.surface_commit.link);
wl_list_remove(&listeners.destroy.link);
}

Expand Down
2 changes: 0 additions & 2 deletions src/input/constraint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class PointerConstraint {
public:
struct Listeners {
std::reference_wrapper<PointerConstraint> parent;
wl_listener set_region = {};
wl_listener surface_commit = {};
wl_listener destroy = {};
explicit Listeners(PointerConstraint& parent) noexcept : parent(parent) {}
};
Expand Down
3 changes: 1 addition & 2 deletions src/input/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ static void cursor_axis_notify(wl_listener* listener, void* data) {
* event. Frame events are sent after regular pointer events to group
* multiple events together. For instance, two axis events may happen at the
* same time, in which case a frame event won't be sent in between. */
static void cursor_frame_notify(wl_listener* listener, void* data) {
static void cursor_frame_notify(wl_listener* listener, void*) {
Cursor& cursor = magpie_container_of(listener, cursor, frame);
(void) data;

/* Notify the client with pointer focus of the frame event. */
wlr_seat_pointer_notify_frame(cursor.seat.wlr);
Expand Down
6 changes: 2 additions & 4 deletions src/input/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
/* This event is raised by the keyboard base wlr_input_device to signal
* the destruction of the wlr_keyboard. It will no longer receive events
* and should be destroyed. */
static void keyboard_handle_destroy(wl_listener* listener, void* data) {
static void keyboard_handle_destroy(wl_listener* listener, void*) {
Keyboard& keyboard = magpie_container_of(listener, keyboard, destroy);
(void) data;

std::vector<Keyboard*>& keyboards = keyboard.seat.keyboards;
(void) std::ranges::remove(keyboards, &keyboard).begin();
Expand Down Expand Up @@ -96,9 +95,8 @@ static void keyboard_handle_key(wl_listener* listener, void* data) {

/* This event is raised when a modifier key, such as shift or alt, is
* pressed. We simply communicate this to the client. */
static void keyboard_handle_modifiers(wl_listener* listener, void* data) {
static void keyboard_handle_modifiers(wl_listener* listener, void*) {
Keyboard& keyboard = magpie_container_of(listener, keyboard, modifiers);
(void) data;

/*
* A seat can only have one keyboard, but this is a limitation of the
Expand Down
2 changes: 1 addition & 1 deletion src/input/seat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@ void Seat::apply_constraint(const wlr_pointer* pointer, double* dx, double* dy)

bool Seat::is_pointer_locked(const wlr_pointer* pointer) const {
return current_constraint.has_value() && pointer->base.type == WLR_INPUT_DEVICE_POINTER &&
current_constraint->get().wlr.type == WLR_POINTER_CONSTRAINT_V1_LOCKED;
current_constraint->get().wlr.type == WLR_POINTER_CONSTRAINT_V1_LOCKED;
}
6 changes: 2 additions & 4 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ static void output_request_state_notify(wl_listener* listener, void* data) {

/* This function is called every time an output is ready to display a frame,
* generally at the output's refresh rate (e.g. 60Hz). */
static void output_frame_notify(wl_listener* listener, void* data) {
static void output_frame_notify(wl_listener* listener, void*) {
Output& output = magpie_container_of(listener, output, frame);
(void) data;

wlr_scene_output* scene_output = wlr_scene_get_scene_output(output.server.scene, &output.wlr);

Expand All @@ -42,9 +41,8 @@ static void output_frame_notify(wl_listener* listener, void* data) {
wlr_scene_output_send_frame_done(scene_output, &now);
}

static void output_destroy_notify(wl_listener* listener, void* data) {
static void output_destroy_notify(wl_listener* listener, void*) {
Output& output = magpie_container_of(listener, output, destroy);
(void) data;

output.server.outputs.erase(&output);
for (const auto* layer : std::as_const(output.layers)) {
Expand Down
3 changes: 1 addition & 2 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,8 @@ static void drm_lease_notify(wl_listener* listener, void* data) {
}
}

void output_layout_change_notify(wl_listener* listener, void* data) {
void output_layout_change_notify(wl_listener* listener, void*) {
Server& server = magpie_container_of(listener, server, output_layout_change);
(void) data;

if (server.num_pending_output_layout_changes > 0) {
return;
Expand Down
18 changes: 6 additions & 12 deletions src/surface/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ static magpie_scene_layer_t magpie_layer_from_wlr_layer(const zwlr_layer_shell_v
}
}

static void subsurface_map_notify(wl_listener* listener, void* data) {
static void subsurface_map_notify(wl_listener* listener, void*) {
LayerSubsurface& subsurface = magpie_container_of(listener, subsurface, map);
(void) data;

wlr_surface_send_enter(subsurface.subsurface.surface, &subsurface.parent.output.wlr);
}

static void subsurface_destroy_notify(wl_listener* listener, void* data) {
static void subsurface_destroy_notify(wl_listener* listener, void*) {
LayerSubsurface& subsurface = magpie_container_of(listener, subsurface, destroy);
(void) data;

subsurface.parent.subsurfaces.erase(&subsurface);
delete &subsurface;
Expand All @@ -57,34 +55,30 @@ LayerSubsurface::~LayerSubsurface() noexcept {
}

/* Called when the surface is mapped, or ready to display on-screen. */
static void wlr_layer_surface_v1_map_notify(wl_listener* listener, void* data) {
static void wlr_layer_surface_v1_map_notify(wl_listener* listener, void*) {
Layer& layer = magpie_container_of(listener, layer, map);
(void) data;

wlr_scene_node_set_enabled(layer.scene_node, true);
wlr_surface_send_enter(layer.get_wlr_surface(), &layer.output.wlr);
}

/* Called when the surface is unmapped, and should no longer be shown. */
static void wlr_layer_surface_v1_unmap_notify(wl_listener* listener, void* data) {
static void wlr_layer_surface_v1_unmap_notify(wl_listener* listener, void*) {
Layer& layer = magpie_container_of(listener, layer, unmap);
(void) data;

wlr_scene_node_set_enabled(layer.scene_node, false);
}

/* Called when the surface is destroyed and should never be shown again. */
static void wlr_layer_surface_v1_destroy_notify(wl_listener* listener, void* data) {
static void wlr_layer_surface_v1_destroy_notify(wl_listener* listener, void*) {
Layer& layer = magpie_container_of(listener, layer, destroy);
(void) data;

layer.output.layers.erase(&layer);
delete &layer;
}

static void wlr_layer_surface_v1_commit_notify(wl_listener* listener, void* data) {
static void wlr_layer_surface_v1_commit_notify(wl_listener* listener, void*) {
Layer& layer = magpie_container_of(listener, layer, commit);
(void) data;

const Server& server = layer.output.server;
const wlr_layer_surface_v1& surface = layer.layer_surface;
Expand Down
2 changes: 2 additions & 0 deletions src/surface/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "surface.hpp"
#include "types.hpp"

#include <functional>
#include <set>

#include "wlr-wrap-start.hpp"
Expand Down
22 changes: 2 additions & 20 deletions src/surface/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

#include <utility>

static void popup_map_notify(wl_listener* listener, void* data) {
static void popup_map_notify(wl_listener* listener, void*) {
Popup& popup = magpie_container_of(listener, popup, map);
(void) data;

wlr_box current = {};
wlr_xdg_surface_get_geometry(popup.wlr.base, &current);
Expand All @@ -25,23 +24,12 @@ static void popup_map_notify(wl_listener* listener, void* data) {
}
}

static void popup_unmap_notify(wl_listener* listener, void* data) {
(void) listener;
(void) data;
}

static void popup_destroy_notify(wl_listener* listener, void* data) {
static void popup_destroy_notify(wl_listener* listener, void*) {
Popup& popup = magpie_container_of(listener, popup, destroy);
(void) data;

delete &popup;
}

static void popup_commit_notify(wl_listener* listener, void* data) {
(void) listener;
(void) data;
}

static void popup_new_popup_notify(wl_listener* listener, void* data) {
const Popup& popup = magpie_container_of(listener, popup, new_popup);

Expand All @@ -59,21 +47,15 @@ Popup::Popup(const Surface& parent, wlr_xdg_popup& wlr) noexcept

listeners.map.notify = popup_map_notify;
wl_signal_add(&wlr.base->surface->events.map, &listeners.map);
listeners.unmap.notify = popup_unmap_notify;
wl_signal_add(&wlr.base->surface->events.unmap, &listeners.unmap);
listeners.destroy.notify = popup_destroy_notify;
wl_signal_add(&wlr.base->events.destroy, &listeners.destroy);
listeners.commit.notify = popup_commit_notify;
wl_signal_add(&wlr.base->surface->events.commit, &listeners.commit);
listeners.new_popup.notify = popup_new_popup_notify;
wl_signal_add(&wlr.base->events.new_popup, &listeners.new_popup);
}

Popup::~Popup() noexcept {
wl_list_remove(&listeners.map.link);
wl_list_remove(&listeners.unmap.link);
wl_list_remove(&listeners.destroy.link);
wl_list_remove(&listeners.commit.link);
wl_list_remove(&listeners.new_popup.link);
}

Expand Down
4 changes: 2 additions & 2 deletions src/surface/popup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "surface.hpp"
#include "types.hpp"

#include <functional>

#include "wlr-wrap-start.hpp"
#include <wlr/types/wlr_xdg_shell.h>
#include "wlr-wrap-end.hpp"
Expand All @@ -13,9 +15,7 @@ class Popup final : public Surface {
struct Listeners {
std::reference_wrapper<Popup> parent;
wl_listener map = {};
wl_listener unmap = {};
wl_listener destroy = {};
wl_listener commit = {};
wl_listener new_popup = {};
explicit Listeners(Popup& parent) noexcept : parent(parent) {}
};
Expand Down
2 changes: 0 additions & 2 deletions src/surface/surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#include "types.hpp"

#include <functional>

#include "wlr-wrap-start.hpp"
#include <wlr/types/wlr_scene.h>
#include "wlr-wrap-end.hpp"
Expand Down
12 changes: 8 additions & 4 deletions src/surface/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <wlr/util/edges.h>
#include "wlr-wrap-end.hpp"

std::optional<const Output*> View::find_output_for_maximize() const {
std::optional<std::reference_wrapper<Output>> View::find_output_for_maximize() const {
const Server& server = get_server();

if (server.outputs.empty()) {
Expand Down Expand Up @@ -62,7 +62,11 @@ std::optional<const Output*> View::find_output_for_maximize() const {
best_output = static_cast<Output*>(wlr_output_layout_get_center_output(server.output_layout)->data);
}

return best_output;
if (best_output == nullptr) {
return {};
}

return std::ref(*best_output);
}

void View::begin_interactive(const CursorMode mode, const uint32_t edges) {
Expand Down Expand Up @@ -223,7 +227,7 @@ bool View::maximize() {
return false;
}

const wlr_box output_box = best_output.value()->usable_area;
const wlr_box output_box = best_output->get().usable_area;

const wlr_box min_size = get_min_size();
if (output_box.width < min_size.width || output_box.height < min_size.height) {
Expand All @@ -249,7 +253,7 @@ bool View::fullscreen() {
return false;
}

const wlr_box output_box = best_output.value()->full_area;
const wlr_box output_box = best_output->get().full_area;

const wlr_box min_size = get_min_size();
if (output_box.width < min_size.width || output_box.height < min_size.height) {
Expand Down
4 changes: 2 additions & 2 deletions src/surface/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct View : Surface {
void toggle_fullscreen();

private:
[[nodiscard]] std::optional<const Output*> find_output_for_maximize() const;
[[nodiscard]] std::optional<std::reference_wrapper<Output>> find_output_for_maximize() const;
void stack();
bool maximize();
bool fullscreen();
Expand Down Expand Up @@ -89,7 +89,7 @@ class XdgView final : public View {
Server& server;
wlr_xdg_toplevel& xdg_toplevel;

XdgView(Server& server, wlr_xdg_toplevel& toplevel) noexcept;
XdgView(Server& server, wlr_xdg_toplevel& wlr) noexcept;
~XdgView() noexcept override;

[[nodiscard]] constexpr wlr_surface* get_wlr_surface() const override;
Expand Down
Loading

0 comments on commit e106dfe

Please sign in to comment.