Skip to content

Commit

Permalink
GTK4. wlr, cffi, hyplrand migration
Browse files Browse the repository at this point in the history
Signed-off-by: Viktar Lukashonak <[email protected]>
  • Loading branch information
LukashonakV committed Oct 31, 2024
1 parent 048c3e2 commit 7086592
Show file tree
Hide file tree
Showing 20 changed files with 231 additions and 389 deletions.
10 changes: 7 additions & 3 deletions include/modules/cffi.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#pragma once

#include <gtkmm/box.h>

#include "AModule.hpp"

namespace waybar::modules {

namespace ffi {
extern "C" {
typedef struct wbcffi_module wbcffi_module;
using wbcffi_module = struct wbcffi_module;

typedef struct {
using wbcffi_init_info = struct {
wbcffi_module* obj;
const char* waybar_version;
GtkWidget* (*get_root_widget)(wbcffi_module*);
void (*queue_update)(wbcffi_module*);
} wbcffi_init_info;
};

struct wbcffi_config_entry {
const char* key;
Expand All @@ -30,10 +32,12 @@ class CFFI final : public AModule {
virtual auto refresh(int signal) -> void override;
virtual auto doAction(const std::string& name) -> void override;
virtual auto update() -> void override;
operator Gtk::Widget&() override;

private:
///
void* cffi_instance_ = nullptr;
Glib::RefPtr<Gtk::Box> const box_;

typedef void*(InitFn)(const ffi::wbcffi_init_info* init_info,
const ffi::wbcffi_config_entry* config_entries, size_t config_entries_len);
Expand Down
7 changes: 3 additions & 4 deletions include/modules/hyprland/backend.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include <sys/socket.h>
#include <sys/un.h>

#include <filesystem>
#include <list>
#include <memory>
#include <mutex>
#include <string>
#include <utility>

#include "util/json.hpp"

Expand Down
5 changes: 0 additions & 5 deletions include/modules/hyprland/window.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#pragma once

#include <fmt/format.h>

#include <string>

#include "AAppIconLabel.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
#include "util/json.hpp"

namespace waybar::modules::hyprland {

Expand Down
16 changes: 0 additions & 16 deletions include/modules/hyprland/windowcreationpayload.hpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
#pragma once

#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <json/value.h>

#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <regex>
#include <string>
#include <variant>
#include <vector>

#include "AModule.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
#include "util/enum.hpp"
#include "util/regex_collection.hpp"

using WindowAddress = std::string;

Expand Down
22 changes: 3 additions & 19 deletions include/modules/hyprland/workspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,8 @@

#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <json/value.h>

#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <regex>
#include <string>
#include <variant>
#include <vector>

#include "AModule.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
#include "modules/hyprland/windowcreationpayload.hpp"
#include "util/enum.hpp"
#include "util/regex_collection.hpp"
#include "modules/hyprland/workspaces.hpp"

using WindowAddress = std::string;

Expand All @@ -44,8 +28,7 @@ class Workspace {
bool isVisible() const { return m_isVisible; };
bool isEmpty() const { return m_windows == 0; };
bool isUrgent() const { return m_isUrgent; };

bool handleClicked(GdkEventButton* bt) const;
void handleToggle(int n_press, double dx, double dy);
void setActive(bool value = true) { m_isActive = value; };
void setPersistentRule(bool value = true) { m_isPersistentRule = value; };
void setPersistentConfig(bool value = true) { m_isPersistentConfig = value; };
Expand Down Expand Up @@ -83,6 +66,7 @@ class Workspace {
Gtk::Button m_button;
Gtk::Box m_content;
Gtk::Label m_label;
Glib::RefPtr<Gtk::GestureClick> const controllClick_;
};

} // namespace waybar::modules::hyprland
12 changes: 0 additions & 12 deletions include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
#pragma once

#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <json/value.h>

#include <cstdint>
#include <map>
#include <memory>
#include <regex>
#include <string>
#include <vector>

#include "AModule.hpp"
#include "bar.hpp"
#include "modules/hyprland/backend.hpp"
#include "modules/hyprland/windowcreationpayload.hpp"
Expand All @@ -23,8 +13,6 @@ using WindowAddress = std::string;

namespace waybar::modules::hyprland {

class Workspaces;

class Workspaces : public AModule, public EventHandler {
public:
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
Expand Down
47 changes: 11 additions & 36 deletions include/modules/wlr/taskbar.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
#pragma once

#include <gdk/gdk.h>
#include <glibmm/refptr.h>
#include <gtkmm/box.h>
#include <giomm/desktopappinfo.h>
#include <gtkmm/button.h>
#include <gtkmm/icontheme.h>
#include <gtkmm/image.h>
#include <gtkmm/label.h>
#include <wayland-client.h>

#include <map>
#include <memory>
#include <string>
#include <unordered_set>
#include <vector>

#include "AModule.hpp"
#include "bar.hpp"
#include "client.hpp"
#include "giomm/desktopappinfo.h"
#include "util/json.hpp"
#include "wlr-foreign-toplevel-management-unstable-v1-client-protocol.h"

namespace waybar::modules::wlr {

struct widget_geometry {
int x, y, w, h;
double x, y;
int w, h;
};

class Taskbar;
Expand All @@ -45,13 +35,13 @@ class Task {
INVALID = (1 << 4)
};
// made public so TaskBar can reorder based on configuration.
Gtk::Button button;
Glib::RefPtr<Gtk::Button> const button;
struct widget_geometry minimize_hint;

private:
static uint32_t global_id;
Glib::RefPtr<Gtk::GestureClick> const controllClick_;

private:
const waybar::Bar &bar_;
const Json::Value &config_;
Taskbar *tbar_;
Expand Down Expand Up @@ -80,15 +70,9 @@ class Task {
std::string app_id_;
uint32_t state_ = 0;

int32_t drag_start_x;
int32_t drag_start_y;
int32_t drag_start_button = -1;

private:
std::string repr() const;
std::string state_string(bool = false) const;
void set_minimize_hint();
void on_button_size_allocated(Gtk::Allocation &alloc);
void set_app_info_from_app_id_list(const std::string &app_id_list);
bool image_load_icon(Gtk::Image &image, const Glib::RefPtr<Gtk::IconTheme> &icon_theme,
Glib::RefPtr<Gio::DesktopAppInfo> app_info, int size);
Expand All @@ -105,7 +89,6 @@ class Task {
bool active() const { return state_ & ACTIVE; }
bool fullscreen() const { return state_ & FULLSCREEN; }

public:
/* Callbacks for the wlr protocol */
void handle_title(const char *);
void handle_app_id(const char *);
Expand All @@ -116,22 +99,14 @@ class Task {
void handle_closed();

/* Callbacks for Gtk events */
bool handle_clicked(GdkEventButton *);
bool handle_button_release(GdkEventButton *);
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_received(const Glib::RefPtr<Gdk::DragContext> &context, int x, int y,
Gtk::SelectionData selection_data, guint info, guint time);
void handleClick(int n_press, double dx, double dy);
bool handleDropData(const Glib::ValueBase &, double, double);

public:
bool operator==(const Task &) const;
bool operator!=(const Task &) const;

public:
void update();

public:
/* Interaction with the tasks */
void maximize(bool);
void minimize(bool);
Expand All @@ -147,6 +122,7 @@ class Taskbar : public waybar::AModule {
Taskbar(const std::string &, const waybar::Bar &, const Json::Value &);
~Taskbar();
void update();
operator Gtk::Widget &() override;

private:
const waybar::Bar &bar_;
Expand All @@ -169,10 +145,9 @@ class Taskbar : public waybar::AModule {
void handle_toplevel_create(struct zwlr_foreign_toplevel_handle_v1 *);
void handle_finished();

public:
void add_button(Gtk::Button &);
void move_button(Gtk::Button &, int);
void remove_button(Gtk::Button &);
void add_button(Glib::RefPtr<Gtk::Button>);
void move_button(Glib::RefPtr<Gtk::Button>, int);
void remove_button(Glib::RefPtr<Gtk::Button>);
void remove_task(uint32_t);

bool show_output(struct wl_output *) const;
Expand Down
12 changes: 3 additions & 9 deletions include/modules/wlr/workspace_manager.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
#pragma once

#include <fmt/format.h>
#include <gtkmm/button.h>
#include <gtkmm/image.h>
#include <gtkmm/label.h>

#include <functional>
#include <map>
#include <memory>
#include <vector>

#include "AModule.hpp"
#include "bar.hpp"
#include "ext-workspace-unstable-v1-client-protocol.h"

Expand Down Expand Up @@ -41,7 +33,7 @@ class Workspace {
auto handle_duplicate() -> void;

auto handle_done() -> void;
auto handle_clicked(GdkEventButton *bt) -> bool;
void handleClick(int n_press, double dx, double dy);
auto show() -> void;
auto hide() -> void;
auto get_button_ref() -> Gtk::Button & { return button_; }
Expand Down Expand Up @@ -75,6 +67,7 @@ class Workspace {
bool persistent_ = false;

Gtk::Button button_;
Glib::RefPtr<Gtk::GestureClick> const controllClick_;
Gtk::Box content_;
Gtk::Label label_;
};
Expand Down Expand Up @@ -133,6 +126,7 @@ class WorkspaceManager : public AModule {
WorkspaceManager(const std::string &id, const waybar::Bar &bar, const Json::Value &config);
~WorkspaceManager() override;
auto update() -> void override;
operator Gtk::Widget &() override;

auto all_outputs() const -> bool { return all_outputs_; }
auto active_only() const -> bool { return active_only_; }
Expand Down
7 changes: 5 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ src_files = files(
'src/config.cpp',
'src/group.cpp',
'src/util/portal.cpp',
'src/util/enum.cpp',
'src/util/prepare_for_sleep.cpp',
'src/util/ustring_clen.cpp',
'src/util/sanitize_str.cpp',
Expand Down Expand Up @@ -262,11 +263,12 @@ man_files += files('man/waybar-sway-language.5.scd',
'man/waybar-sway-scratchpad.5.scd',
'man/waybar-sway-window.5.scd',
'man/waybar-sway-workspaces.5.scd')
if 1 == 0

add_project_arguments('-DHAVE_WLR_TASKBAR', language: 'cpp')
src_files += files('src/modules/wlr/taskbar.cpp')
man_files += files('man/waybar-wlr-taskbar.5.scd')

if 1 == 0
add_project_arguments('-DHAVE_RIVER', language: 'cpp')
src_files += files('src/modules/river/layout.cpp',
'src/modules/river/mode.cpp',
Expand All @@ -282,7 +284,7 @@ src_files += files('src/modules/dwl/tags.cpp',
'src/modules/dwl/window.cpp')
man_files += files('man/waybar-dwl-tags.5.scd',
'man/waybar-dwl-window.5.scd')
if 1 == 0

add_project_arguments('-DHAVE_HYPRLAND', language: 'cpp')
src_files += files('src/modules/hyprland/backend.cpp',
'src/modules/hyprland/language.cpp',
Expand All @@ -296,6 +298,7 @@ man_files += files('man/waybar-hyprland-language.5.scd',
'man/waybar-hyprland-window.5.scd',
'man/waybar-hyprland-workspaces.5.scd')

if 1 == 0
if get_option('niri')
add_project_arguments('-DHAVE_NIRI', language: 'cpp')
src_files += files(
Expand Down
Loading

0 comments on commit 7086592

Please sign in to comment.