159 lines
4.0 KiB
C
Raw Normal View History

2025-12-28 03:14:31 +01:00
/*
* DWN - Desktop Window Manager
* retoor <retoor@molodetz.nl>
* System tray widgets (WiFi, Audio, etc.) and XEmbed protocol
2025-12-28 03:14:31 +01:00
*/
#ifndef DWN_SYSTRAY_H
#define DWN_SYSTRAY_H
#include "dwn.h"
#include <stdbool.h>
#define MAX_WIFI_NETWORKS 20
#define MAX_TRAY_ICONS 32
#define TRAY_ICON_SIZE 22
#define TRAY_ICON_SPACING 4
#define SYSTEM_TRAY_REQUEST_DOCK 0
#define SYSTEM_TRAY_BEGIN_MESSAGE 1
#define SYSTEM_TRAY_CANCEL_MESSAGE 2
#define XEMBED_EMBEDDED_NOTIFY 0
#define XEMBED_WINDOW_ACTIVATE 1
#define XEMBED_WINDOW_DEACTIVATE 2
#define XEMBED_REQUEST_FOCUS 3
#define XEMBED_FOCUS_IN 4
#define XEMBED_FOCUS_OUT 5
#define XEMBED_MAPPED (1 << 0)
#define XEMBED_PROTOCOL_VERSION 0
typedef struct {
Window window;
int x;
int width;
int height;
bool mapped;
} TrayIcon;
extern TrayIcon tray_icons[MAX_TRAY_ICONS];
extern int tray_icon_count;
extern Window tray_selection_owner;
2025-12-28 03:14:31 +01:00
typedef struct {
char ssid[64];
int signal;
char security[32];
2025-12-28 03:14:31 +01:00
bool connected;
} WifiNetwork;
typedef struct {
bool enabled;
bool connected;
char current_ssid[64];
int signal_strength;
WifiNetwork networks[MAX_WIFI_NETWORKS];
int network_count;
long last_scan;
2025-12-28 03:14:31 +01:00
} WifiState;
typedef struct {
int volume;
2025-12-28 03:14:31 +01:00
bool muted;
} AudioState;
typedef struct {
bool present;
bool charging;
int percentage;
int time_remaining;
2025-12-28 03:14:31 +01:00
} BatteryState;
typedef struct {
Window window;
int x, y;
int width, height;
bool visible;
bool dragging;
} VolumeSlider;
typedef struct {
Window window;
int x, y;
int width, height;
int item_count;
int hovered_item;
bool visible;
void (*on_select)(int index);
} DropdownMenu;
extern WifiState wifi_state;
extern AudioState audio_state;
extern BatteryState battery_state;
extern DropdownMenu *wifi_menu;
extern VolumeSlider *volume_slider;
void systray_init(void);
void systray_cleanup(void);
void wifi_update_state(void);
void wifi_scan_networks(void);
void wifi_connect(const char *ssid);
void wifi_disconnect(void);
const char *wifi_get_icon(void);
void audio_update_state(void);
void audio_set_volume(int volume);
void audio_toggle_mute(void);
const char *audio_get_icon(void);
void battery_update_state(void);
const char *battery_get_icon(void);
VolumeSlider *volume_slider_create(int x, int y);
void volume_slider_destroy(VolumeSlider *slider);
void volume_slider_show(VolumeSlider *slider);
void volume_slider_hide(VolumeSlider *slider);
void volume_slider_render(VolumeSlider *slider);
void volume_slider_handle_click(VolumeSlider *slider, int x, int y);
void volume_slider_handle_motion(VolumeSlider *slider, int x, int y);
void volume_slider_handle_release(VolumeSlider *slider);
DropdownMenu *dropdown_create(int x, int y, int width);
void dropdown_destroy(DropdownMenu *menu);
void dropdown_show(DropdownMenu *menu);
void dropdown_hide(DropdownMenu *menu);
void dropdown_add_item(DropdownMenu *menu, const char *label);
void dropdown_render(DropdownMenu *menu);
int dropdown_hit_test(DropdownMenu *menu, int x, int y);
void dropdown_handle_click(DropdownMenu *menu, int x, int y);
void dropdown_handle_motion(DropdownMenu *menu, int x, int y);
void systray_render(Panel *panel, int x, int *width);
int systray_get_width(void);
void systray_handle_click(int x, int y, int button);
int systray_hit_test(int x);
2025-12-28 03:14:31 +01:00
void systray_update(void);
void systray_lock(void);
void systray_unlock(void);
BatteryState systray_get_battery_snapshot(void);
AudioState systray_get_audio_snapshot(void);
void xembed_init(void);
void xembed_cleanup(void);
bool xembed_dock_icon(Window icon_win);
void xembed_remove_icon(Window icon_win);
TrayIcon *xembed_find_icon(Window icon_win);
void xembed_send_message(Window icon, long message, long detail, long data1, long data2);
int xembed_get_icons_width(void);
void xembed_render_icons(Panel *panel, int x);
void xembed_handle_click(int x, int y, int button);
int xembed_hit_test(int x);
void xembed_update_icon_state(Window icon_win);
#endif