fix: lint

This commit is contained in:
Alex 2022-10-26 17:26:15 +02:00
parent 930a3e168b
commit 2d7e21ed7d
3 changed files with 33 additions and 35 deletions

View File

@ -111,9 +111,10 @@ class Task {
bool handle_clicked(GdkEventButton *); bool handle_clicked(GdkEventButton *);
bool handle_button_release(GdkEventButton *); bool handle_button_release(GdkEventButton *);
bool handle_motion_notify(GdkEventMotion *); bool handle_motion_notify(GdkEventMotion *);
void handle_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection_data, guint info, guint time); void handle_drag_data_get(const Glib::RefPtr<Gdk::DragContext> &context,
void handle_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData selection_data, guint info, guint time); Gtk::SelectionData &selection_data, guint info, guint time);
void handle_drag_data_received(const Glib::RefPtr<Gdk::DragContext> &context, int x, int y,
Gtk::SelectionData selection_data, guint info, guint time);
public: public:
bool operator==(const Task &) const; bool operator==(const Task &) const;

View File

@ -31,17 +31,18 @@ auto waybar::modules::Memory::update() -> void {
} }
if (memtotal > 0 && memfree >= 0) { if (memtotal > 0 && memfree >= 0) {
float total_ram_gigabytes = 0.01*round(memtotal / 10485.76); // 100*10485.76 = 2^20 = 1024^2 = GiB/KiB float total_ram_gigabytes =
float total_swap_gigabytes = 0.01*round(swaptotal / 10485.76); 0.01 * round(memtotal / 10485.76); // 100*10485.76 = 2^20 = 1024^2 = GiB/KiB
float total_swap_gigabytes = 0.01 * round(swaptotal / 10485.76);
int used_ram_percentage = 100 * (memtotal - memfree) / memtotal; int used_ram_percentage = 100 * (memtotal - memfree) / memtotal;
int used_swap_percentage = 0; int used_swap_percentage = 0;
if (swaptotal && swapfree) { if (swaptotal && swapfree) {
used_swap_percentage = 100 * (swaptotal - swapfree) / swaptotal; used_swap_percentage = 100 * (swaptotal - swapfree) / swaptotal;
} }
float used_ram_gigabytes = 0.01*round((memtotal - memfree) / 10485.76); float used_ram_gigabytes = 0.01 * round((memtotal - memfree) / 10485.76);
float used_swap_gigabytes = 0.01*round((swaptotal - swapfree) / 10485.76); float used_swap_gigabytes = 0.01 * round((swaptotal - swapfree) / 10485.76);
float available_ram_gigabytes = 0.01*round(memfree / 10485.76); float available_ram_gigabytes = 0.01 * round(memfree / 10485.76);
float available_swap_gigabytes = 0.01*round(swapfree / 10485.76); float available_swap_gigabytes = 0.01 * round(swapfree / 10485.76);
auto format = format_; auto format = format_;
auto state = getState(used_ram_percentage); auto state = getState(used_ram_percentage);

View File

@ -252,8 +252,7 @@ static const struct zwlr_foreign_toplevel_handle_v1_listener toplevel_handle_imp
}; };
static const std::vector<Gtk::TargetEntry> target_entries = { static const std::vector<Gtk::TargetEntry> target_entries = {
Gtk::TargetEntry("WAYBAR_TOPLEVEL", Gtk::TARGET_SAME_APP, 0) Gtk::TargetEntry("WAYBAR_TOPLEVEL", Gtk::TARGET_SAME_APP, 0)};
};
Task::Task(const waybar::Bar &bar, const Json::Value &config, Taskbar *tbar, Task::Task(const waybar::Bar &bar, const Json::Value &config, Taskbar *tbar,
struct zwlr_foreign_toplevel_handle_v1 *tl_handle, struct wl_seat *seat) struct zwlr_foreign_toplevel_handle_v1 *tl_handle, struct wl_seat *seat)
@ -317,15 +316,18 @@ Task::Task(const waybar::Bar &bar, const Json::Value &config, Taskbar *tbar,
button_.add_events(Gdk::BUTTON_PRESS_MASK); button_.add_events(Gdk::BUTTON_PRESS_MASK);
button_.signal_button_press_event().connect(sigc::mem_fun(*this, &Task::handle_clicked), false); button_.signal_button_press_event().connect(sigc::mem_fun(*this, &Task::handle_clicked), false);
button_.signal_button_release_event().connect(sigc::mem_fun(*this, &Task::handle_button_release), false); button_.signal_button_release_event().connect(sigc::mem_fun(*this, &Task::handle_button_release),
false);
button_.signal_motion_notify_event().connect(sigc::mem_fun(*this, &Task::handle_motion_notify), false); button_.signal_motion_notify_event().connect(sigc::mem_fun(*this, &Task::handle_motion_notify),
false);
button_.drag_source_set(target_entries, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE); button_.drag_source_set(target_entries, Gdk::BUTTON1_MASK, Gdk::ACTION_MOVE);
button_.drag_dest_set(target_entries, Gtk::DEST_DEFAULT_ALL, Gdk::ACTION_MOVE); button_.drag_dest_set(target_entries, Gtk::DEST_DEFAULT_ALL, Gdk::ACTION_MOVE);
button_.signal_drag_data_get().connect(sigc::mem_fun(*this, &Task::handle_drag_data_get), false); button_.signal_drag_data_get().connect(sigc::mem_fun(*this, &Task::handle_drag_data_get), false);
button_.signal_drag_data_received().connect(sigc::mem_fun(*this, &Task::handle_drag_data_received), false); button_.signal_drag_data_received().connect(
sigc::mem_fun(*this, &Task::handle_drag_data_received), false);
} }
Task::~Task() { Task::~Task() {
@ -556,47 +558,41 @@ bool Task::handle_button_release(GdkEventButton *bt) {
} }
bool Task::handle_motion_notify(GdkEventMotion *mn) { bool Task::handle_motion_notify(GdkEventMotion *mn) {
if (drag_start_button == -1) if (drag_start_button == -1) return false;
return false;
if ( button_.drag_check_threshold(drag_start_x, drag_start_y, mn->x, mn->y)) { if (button_.drag_check_threshold(drag_start_x, drag_start_y, mn->x, mn->y)) {
/* start drag in addition to other assigned action */ /* start drag in addition to other assigned action */
auto target_list = Gtk::TargetList::create(target_entries); auto target_list = Gtk::TargetList::create(target_entries);
auto refptr = Glib::RefPtr<Gtk::TargetList>(target_list); auto refptr = Glib::RefPtr<Gtk::TargetList>(target_list);
auto drag_context = button_.drag_begin(refptr, Gdk::DragAction::ACTION_MOVE, drag_start_button, (GdkEvent*)mn); auto drag_context =
button_.drag_begin(refptr, Gdk::DragAction::ACTION_MOVE, drag_start_button, (GdkEvent *)mn);
} }
return false; return false;
} }
void Task::handle_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context, Gtk::SelectionData& selection_data, guint info, guint time) void Task::handle_drag_data_get(const Glib::RefPtr<Gdk::DragContext> &context,
{ Gtk::SelectionData &selection_data, guint info, guint time) {
spdlog::debug("drag_data_get"); spdlog::debug("drag_data_get");
void* button_addr = (void*)&this->button_; void *button_addr = (void *)&this->button_;
selection_data.set( selection_data.set("WAYBAR_TOPLEVEL", 32, (const guchar *)&button_addr, sizeof(gpointer));
"WAYBAR_TOPLEVEL",
32,
(const guchar *)&button_addr,
sizeof (gpointer));
} }
void Task::handle_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, Gtk::SelectionData selection_data, guint info, guint time) void Task::handle_drag_data_received(const Glib::RefPtr<Gdk::DragContext> &context, int x, int y,
{ Gtk::SelectionData selection_data, guint info, guint time) {
spdlog::debug("drag_data_received"); spdlog::debug("drag_data_received");
gpointer handle = *(gpointer*)selection_data.get_data(); gpointer handle = *(gpointer *)selection_data.get_data();
auto dragged_button = (Gtk::Button*)handle; auto dragged_button = (Gtk::Button *)handle;
if(dragged_button == &this->button_) if (dragged_button == &this->button_) return;
return;
auto parent_of_dragged = dragged_button->get_parent(); auto parent_of_dragged = dragged_button->get_parent();
auto parent_of_dest = this->button_.get_parent(); auto parent_of_dest = this->button_.get_parent();
if(parent_of_dragged != parent_of_dest) if (parent_of_dragged != parent_of_dest) return;
return;
auto box = (Gtk::Box*)parent_of_dragged; auto box = (Gtk::Box *)parent_of_dragged;
auto position_prop = box->child_property_position(this->button_); auto position_prop = box->child_property_position(this->button_);
auto position = position_prop.get_value(); auto position = position_prop.get_value();