system_will_sleep event and scripts are not executed during sleep

This commit is contained in:
Felix Kratz 2021-11-13 13:56:26 +01:00
parent ac376fffe3
commit c648823b9e
8 changed files with 32 additions and 2 deletions

View file

@ -26,6 +26,7 @@ void bar_manager_init(struct bar_manager* bar_manager) {
bar_manager->blur_radius = 0;
bar_manager->margin = 0;
bar_manager->frozen = false;
bar_manager->sleeps = false;
bar_manager->window_level = NSFloatingWindowLevel;
bar_manager->topmost = false;
bar_manager->picky_redraw = false;
@ -304,7 +305,7 @@ void bar_manager_update_space_components(struct bar_manager* bar_manager, bool f
}
void bar_manager_update(struct bar_manager* bar_manager, bool forced) {
if (bar_manager->frozen && !forced) return;
if ((bar_manager->frozen && !forced) || bar_manager->sleeps) return;
bool needs_refresh = false;
for (int i = 0; i < bar_manager->bar_item_count; i++) {
needs_refresh |= bar_item_update(bar_manager->bar_items[i], NULL, forced);
@ -390,7 +391,13 @@ void bar_manager_handle_display_change(struct bar_manager* bar_manager) {
bar_manager_custom_events_trigger(bar_manager, COMMAND_SUBSCRIBE_DISPLAY_CHANGE);
}
void bar_manager_handle_system_will_sleep(struct bar_manager* bar_manager) {
bar_manager_custom_events_trigger(bar_manager, COMMAND_SUBSCRIBE_SYSTEM_WILL_SLEEP);
bar_manager->sleeps = true;
}
void bar_manager_handle_system_woke(struct bar_manager* bar_manager) {
bar_manager->sleeps = false;
bar_manager_update_space_components(bar_manager, false);
bar_manager_custom_events_trigger(bar_manager, COMMAND_SUBSCRIBE_SYSTEM_WOKE);
bar_manager_refresh(bar_manager, true);

View file

@ -12,6 +12,7 @@ typedef SHELL_TIMER_CALLBACK(shell_timer_callback);
struct bar_manager {
bool any_bar_hidden;
bool frozen;
bool sleeps;
bool picky_redraw;
bool topmost;
bool font_smoothing;
@ -76,6 +77,7 @@ void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager);
void bar_manager_handle_space_change(struct bar_manager* bar_manager);
void bar_manager_handle_display_change(struct bar_manager* bar_manager);
void bar_manager_handle_system_woke(struct bar_manager* bar_manager);
void bar_manager_handle_system_will_sleep(struct bar_manager* bar_manager);
struct bar_item* bar_manager_get_item_by_point(struct bar_manager* bar_manager, CGPoint point, uint32_t sid);

View file

@ -18,9 +18,9 @@ void custom_events_init(struct custom_events* custom_events) {
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_ENTERED), NULL);
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_EXITED), NULL);
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_MOUSE_CLICKED), NULL);
custom_events_append(custom_events, string_copy(COMMAND_SUBSCRIBE_SYSTEM_WILL_SLEEP), NULL);
}
void custom_events_append(struct custom_events* custom_events, char* name, char* notification) {
if (custom_events_get_flag_for_name(custom_events, name) > 0) return;
custom_events->count++;

View file

@ -8,6 +8,7 @@
#define UPDATE_MOUSE_ENTERED 1ULL << 4
#define UPDATE_MOUSE_EXITED 1ULL << 5
#define UPDATE_MOUSE_CLICKED 1ULL << 6
#define UPDATE_SYSTEM_WILL_SLEEP 1ULL << 7
extern void* g_workspace_context;

View file

@ -84,6 +84,12 @@ static EVENT_CALLBACK(EVENT_HANDLER_SYSTEM_WOKE) {
return EVENT_SUCCESS;
}
static EVENT_CALLBACK(EVENT_HANDLER_SYSTEM_WILL_SLEEP) {
debug("%s:\n", __FUNCTION__);
bar_manager_handle_system_will_sleep(&g_bar_manager);
return EVENT_SUCCESS;
}
static EVENT_CALLBACK(EVENT_HANDLER_SHELL_REFRESH) {
debug("%s\n", __FUNCTION__);
bar_manager_update(&g_bar_manager, false);

View file

@ -15,6 +15,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_RESIZED);
static EVENT_CALLBACK(EVENT_HANDLER_DISPLAY_CHANGED);
static EVENT_CALLBACK(EVENT_HANDLER_MENU_BAR_HIDDEN_CHANGED);
static EVENT_CALLBACK(EVENT_HANDLER_SYSTEM_WOKE);
static EVENT_CALLBACK(EVENT_HANDLER_SYSTEM_WILL_SLEEP);
static EVENT_CALLBACK(EVENT_HANDLER_SHELL_REFRESH);
static EVENT_CALLBACK(EVENT_HANDLER_DAEMON_MESSAGE);
static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP);
@ -42,6 +43,7 @@ enum event_type {
DISPLAY_CHANGED,
MENU_BAR_HIDDEN_CHANGED,
SYSTEM_WOKE,
SYSTEM_WILL_SLEEP,
SHELL_REFRESH,
DAEMON_MESSAGE,
MOUSE_UP,
@ -64,6 +66,7 @@ static const char *event_type_str[] = {
[DISPLAY_CHANGED] = "display_changed",
[MENU_BAR_HIDDEN_CHANGED] = "menu_bar_hidden_changed",
[SYSTEM_WOKE] = "system_woke",
[SYSTEM_WILL_SLEEP] = "system_will_sleep",
[SHELL_REFRESH] = "shell_refresh",
[DAEMON_MESSAGE] = "daemon_message",
[MOUSE_UP] = "mouse_up",
@ -89,6 +92,7 @@ static event_callback *event_handler[] = {
[MENU_BAR_HIDDEN_CHANGED] = EVENT_HANDLER_MENU_BAR_HIDDEN_CHANGED,
[SYSTEM_WOKE] = EVENT_HANDLER_SYSTEM_WOKE,
[SYSTEM_WILL_SLEEP] = EVENT_HANDLER_SYSTEM_WILL_SLEEP,
[SHELL_REFRESH] = EVENT_HANDLER_SHELL_REFRESH,
[DAEMON_MESSAGE] = EVENT_HANDLER_DAEMON_MESSAGE,
};

View file

@ -75,6 +75,7 @@
#define COMMAND_SUBSCRIBE_SPACE_CHANGE "space_change"
#define COMMAND_SUBSCRIBE_DISPLAY_CHANGE "display_change"
#define COMMAND_SUBSCRIBE_SYSTEM_WOKE "system_woke"
#define COMMAND_SUBSCRIBE_SYSTEM_WILL_SLEEP "system_will_sleep"
#define COMMAND_SUBSCRIBE_MOUSE_ENTERED "mouse.entered"
#define COMMAND_SUBSCRIBE_MOUSE_EXITED "mouse.exited"
#define COMMAND_SUBSCRIBE_MOUSE_CLICKED "mouse.clicked"

View file

@ -38,6 +38,10 @@ void workspace_create_custom_observer (void **context, char* notification) {
selector:@selector(appSwitched:)
name:NSWorkspaceDidActivateApplicationNotification
object:nil];
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
selector:@selector(willSleep:)
name:NSWorkspaceWillSleepNotification
object:nil];
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
selector:@selector(didWake:)
name:NSWorkspaceDidWakeNotification
@ -71,6 +75,11 @@ void workspace_create_custom_observer (void **context, char* notification) {
event_loop_post(&g_event_loop, event);
}
- (void)willSleep:(NSNotification *)notification {
struct event *event = event_create(&g_event_loop, SYSTEM_WILL_SLEEP, NULL);
event_loop_post(&g_event_loop, event);
}
- (void)didWake:(NSNotification *)notification {
struct event *event = event_create(&g_event_loop, SYSTEM_WOKE, NULL);
event_loop_post(&g_event_loop, event);