Files

185 lines
4.7 KiB
C++
Raw Permalink Normal View History

#pragma once
2022-04-06 08:37:19 +02:00
#include <gdk/gdk.h>
#include <glibmm/refptr.h>
#include <gtkmm/box.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"
2021-08-17 04:31:17 +03:00
#include "giomm/desktopappinfo.h"
#include "util/icon_loader.hpp"
#include "util/json.hpp"
#include "wlr-foreign-toplevel-management-unstable-v1-client-protocol.h"
namespace waybar::modules::wlr {
2024-08-04 22:49:51 -06:00
struct widget_geometry {
2024-08-26 04:44:22 -06:00
int x, y, w, h;
2024-08-04 22:49:51 -06:00
};
class Taskbar;
2022-04-06 08:37:19 +02:00
class Task {
public:
2026-02-04 09:24:14 +01:00
Task(const waybar::Bar&, const Json::Value&, Taskbar*, struct zwlr_foreign_toplevel_handle_v1*,
struct wl_seat*);
2022-04-06 08:37:19 +02:00
~Task();
2022-04-06 08:37:19 +02:00
public:
enum State {
MAXIMIZED = (1 << 0),
MINIMIZED = (1 << 1),
ACTIVE = (1 << 2),
FULLSCREEN = (1 << 3),
INVALID = (1 << 4)
};
2023-01-10 17:32:10 +00:00
// made public so TaskBar can reorder based on configuration.
Gtk::Button button;
2024-08-04 22:49:51 -06:00
struct widget_geometry minimize_hint;
2022-04-06 08:37:19 +02:00
private:
static uint32_t global_id;
2022-04-06 08:37:19 +02:00
private:
2026-02-04 09:24:14 +01:00
const waybar::Bar& bar_;
const Json::Value& config_;
Taskbar* tbar_;
struct zwlr_foreign_toplevel_handle_v1* handle_;
struct wl_seat* seat_;
2022-04-06 08:37:19 +02:00
uint32_t id_;
2022-04-06 08:37:19 +02:00
Gtk::Box content_;
Gtk::Image icon_;
Gtk::Label text_before_;
Gtk::Label text_after_;
Glib::RefPtr<Gio::DesktopAppInfo> app_info_;
bool button_visible_ = false;
bool ignored_ = false;
2022-04-06 08:37:19 +02:00
bool with_icon_ = false;
bool with_name_ = false;
std::string format_before_;
std::string format_after_;
2022-04-06 08:37:19 +02:00
std::string format_tooltip_;
2022-04-06 08:37:19 +02:00
std::string name_;
std::string title_;
std::string app_id_;
uint32_t state_ = 0;
int32_t drag_start_x;
int32_t drag_start_y;
int32_t drag_start_button = -1;
2022-04-06 08:37:19 +02:00
private:
std::string repr() const;
std::string state_string(bool = false) const;
2024-08-04 22:49:51 -06:00
void set_minimize_hint();
2026-02-04 09:24:14 +01:00
void on_button_size_allocated(Gtk::Allocation& alloc);
2022-04-06 08:37:19 +02:00
void hide_if_ignored();
2022-04-06 08:37:19 +02:00
public:
/* Getter functions */
uint32_t id() const { return id_; }
std::string title() const { return title_; }
std::string app_id() const { return app_id_; }
uint32_t state() const { return state_; }
bool maximized() const { return state_ & MAXIMIZED; }
bool minimized() const { return state_ & MINIMIZED; }
bool active() const { return state_ & ACTIVE; }
bool fullscreen() const { return state_ & FULLSCREEN; }
2022-04-06 08:37:19 +02:00
public:
/* Callbacks for the wlr protocol */
2026-02-04 09:24:14 +01:00
void handle_title(const char*);
void handle_app_id(const char*);
void handle_output_enter(struct wl_output*);
void handle_output_leave(struct wl_output*);
void handle_state(struct wl_array*);
2022-04-06 08:37:19 +02:00
void handle_done();
void handle_closed();
2022-04-06 08:37:19 +02:00
/* Callbacks for Gtk events */
2026-02-04 09:24:14 +01:00
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,
2022-10-26 17:26:15 +02:00
Gtk::SelectionData selection_data, guint info, guint time);
2022-04-06 08:37:19 +02:00
public:
2026-02-04 09:24:14 +01:00
bool operator==(const Task&) const;
bool operator!=(const Task&) const;
2022-04-06 08:37:19 +02:00
public:
void update();
2022-04-06 08:37:19 +02:00
public:
/* Interaction with the tasks */
void maximize(bool);
void minimize(bool);
void activate();
void fullscreen(bool);
void close();
};
using TaskPtr = std::unique_ptr<Task>;
2022-04-06 08:37:19 +02:00
class Taskbar : public waybar::AModule {
public:
2026-02-04 09:24:14 +01:00
Taskbar(const std::string&, const waybar::Bar&, const Json::Value&);
2022-04-06 08:37:19 +02:00
~Taskbar();
void update();
2022-04-06 08:37:19 +02:00
private:
2026-02-04 09:24:14 +01:00
const waybar::Bar& bar_;
2022-04-06 08:37:19 +02:00
Gtk::Box box_;
std::vector<TaskPtr> tasks_;
IconLoader icon_loader_;
2022-04-06 08:37:19 +02:00
std::unordered_set<std::string> ignore_list_;
std::map<std::string, std::string> app_ids_replace_map_;
2026-02-04 09:24:14 +01:00
struct zwlr_foreign_toplevel_manager_v1* manager_;
struct wl_seat* seat_;
2022-04-06 08:37:19 +02:00
public:
/* Callbacks for global registration */
2026-02-04 09:24:14 +01:00
void register_manager(struct wl_registry*, uint32_t name, uint32_t version);
void register_seat(struct wl_registry*, uint32_t name, uint32_t version);
2022-04-06 08:37:19 +02:00
/* Callbacks for the wlr protocol */
2026-02-04 09:24:14 +01:00
void handle_toplevel_create(struct zwlr_foreign_toplevel_handle_v1*);
2022-04-06 08:37:19 +02:00
void handle_finished();
2022-04-06 08:37:19 +02:00
public:
2026-02-04 09:24:14 +01:00
void add_button(Gtk::Button&);
void move_button(Gtk::Button&, int);
void remove_button(Gtk::Button&);
2022-04-06 08:37:19 +02:00
void remove_task(uint32_t);
2026-02-04 09:24:14 +01:00
bool show_output(struct wl_output*) const;
2022-04-06 08:37:19 +02:00
bool all_outputs() const;
2026-02-04 09:24:14 +01:00
const IconLoader& icon_loader() const;
const std::unordered_set<std::string>& ignore_list() const;
const std::map<std::string, std::string>& app_ids_replace_map() const;
};
} /* namespace waybar::modules::wlr */