mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-10 05:44:16 +00:00
move refresh logic to improve performance on multi monitor setups
This commit is contained in:
parent
e659b15f17
commit
5ba9ad9e0f
6 changed files with 47 additions and 45 deletions
6
makefile
6
makefile
|
@ -20,6 +20,12 @@ install: clean $(BINS)
|
|||
chmod +x ~/.config/sketchybar/sketchybarrc
|
||||
chmod +x ~/.config/sketchybar/plugins/*
|
||||
echo "Install complete..."
|
||||
|
||||
update: BUILD_FLAGS=-std=c99 -Wall -DNDEBUG -O2 -fvisibility=hidden -mmacosx-version-min=10.13
|
||||
update: clean $(BINS)
|
||||
rm /usr/local/bin/sketchybar
|
||||
ln ./bin/sketchybar /usr/local/bin/sketchybar
|
||||
echo "Update complete... ~/.config/ folder not touched and might need update too...."
|
||||
|
||||
stats: BUILD_FLAGS=-std=c99 -Wall -DSTATS -DNDEBUG -O2 -fvisibility=hidden -mmacosx-version-min=10.13
|
||||
stats: clean $(BINS)
|
||||
|
|
30
src/bar.c
30
src/bar.c
|
@ -1,20 +1,7 @@
|
|||
#include "bar.h"
|
||||
|
||||
extern struct event_loop g_event_loop;
|
||||
extern struct bar_manager g_bar_manager;
|
||||
|
||||
static TIMER_CALLBACK(timer_handler)
|
||||
{
|
||||
struct event *event = event_create(&g_event_loop, BAR_REFRESH, NULL);
|
||||
event_loop_post(&g_event_loop, event);
|
||||
}
|
||||
|
||||
static SHELL_TIMER_CALLBACK(shell_timer_handler)
|
||||
{
|
||||
struct event *event = event_create(&g_event_loop, SHELL_REFRESH, NULL);
|
||||
event_loop_post(&g_event_loop, event);
|
||||
}
|
||||
|
||||
static CTFontRef bar_create_font(char *cstring)
|
||||
{
|
||||
float size = 10.0f;
|
||||
|
@ -344,28 +331,13 @@ struct bar *bar_create(uint32_t did)
|
|||
SLSSetMouseEventEnableFlags(g_connection, bar->id, false);
|
||||
SLSSetWindowLevel(g_connection, bar->id, CGWindowLevelForKey(4));
|
||||
bar->context = SLWindowContextCreate(g_connection, bar->id, 0);
|
||||
|
||||
int refresh_frequency = 1;
|
||||
int shell_refresh_frequency = 1;
|
||||
bar->refresh_timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + refresh_frequency, refresh_frequency, 0, 0, timer_handler, NULL);
|
||||
bar->shell_refresh_timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + shell_refresh_frequency, shell_refresh_frequency, 0, 0, shell_timer_handler, NULL);
|
||||
|
||||
CFRunLoopAddTimer(CFRunLoopGetMain(), bar->refresh_timer, kCFRunLoopCommonModes);
|
||||
CFRunLoopAddTimer(CFRunLoopGetMain(), bar->shell_refresh_timer, kCFRunLoopCommonModes);
|
||||
|
||||
|
||||
bar_refresh(bar);
|
||||
|
||||
return bar;
|
||||
}
|
||||
|
||||
void bar_destroy(struct bar *bar)
|
||||
{
|
||||
CFRunLoopRemoveTimer(CFRunLoopGetMain(), bar->refresh_timer, kCFRunLoopCommonModes);
|
||||
CFRunLoopTimerInvalidate(bar->refresh_timer);
|
||||
|
||||
CFRunLoopRemoveTimer(CFRunLoopGetMain(), bar->shell_refresh_timer, kCFRunLoopCommonModes);
|
||||
CFRunLoopTimerInvalidate(bar->shell_refresh_timer);
|
||||
|
||||
CGContextRelease(bar->context);
|
||||
SLSReleaseWindow(g_connection, bar->id);
|
||||
free(bar);
|
||||
|
|
|
@ -22,15 +22,6 @@ extern CGError CGSNewRegionWithRect(CGRect *rect, CFTypeRef *outRegion);
|
|||
#define kCGSIgnoreForExposeTagBit (1 << 7)
|
||||
#define kCGSStickyTagBit (1 << 11)
|
||||
|
||||
#define POWER_CALLBACK(name) void name(void *context)
|
||||
typedef POWER_CALLBACK(power_callback);
|
||||
|
||||
#define TIMER_CALLBACK(name) void name(CFRunLoopTimerRef timer, void *context)
|
||||
typedef TIMER_CALLBACK(timer_callback);
|
||||
|
||||
#define SHELL_TIMER_CALLBACK(name) void name(CFRunLoopTimerRef timer, void *context)
|
||||
typedef SHELL_TIMER_CALLBACK(shell_timer_callback);
|
||||
|
||||
#define ALIGN_NONE 0
|
||||
#define ALIGN_LEFT 1
|
||||
#define ALIGN_RIGHT 2
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
#ifndef BAR_ITEM_H
|
||||
#define BAR_ITEM_H
|
||||
|
||||
#define BAR_ITEM 'i'
|
||||
#define BAR_ITEM 'i'
|
||||
#define BAR_COMPONENT 'c'
|
||||
#define BAR_PLUGIN 'p'
|
||||
#define BAR_PLUGIN 'p'
|
||||
|
||||
#define UPDATE_FRONT_APP_SWITCHED 1
|
||||
#define UPDATE_WINDOW_FOCUS 1 << 1
|
||||
#define UPDATE_SPACE_CHANGE 1 << 2
|
||||
#define UPDATE_DISPLAY_CHANGE 1 << 3
|
||||
#define UPDATE_SYSTEM_WOKE 1 << 4
|
||||
#define UPDATE_TITLE_CHANGE 1 << 5
|
||||
#define UPDATE_WINDOW_FOCUS 1 << 1
|
||||
#define UPDATE_SPACE_CHANGE 1 << 2
|
||||
#define UPDATE_DISPLAY_CHANGE 1 << 3
|
||||
#define UPDATE_SYSTEM_WOKE 1 << 4
|
||||
#define UPDATE_TITLE_CHANGE 1 << 5
|
||||
|
||||
struct bar_item {
|
||||
bool nospace;
|
||||
|
@ -22,9 +22,12 @@ struct bar_item {
|
|||
uint32_t associated_display;
|
||||
uint32_t associated_space;
|
||||
uint32_t update_frequency;
|
||||
|
||||
// Execute with exec_fork, callback from command via messages
|
||||
char* script;
|
||||
char* script_path;
|
||||
char* on_click_script;
|
||||
char* on_click_script_path;
|
||||
|
||||
// Name by which to refer to the bar_item in the configuration
|
||||
char* name;
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
#include "bar_manager.h"
|
||||
|
||||
extern struct event_loop g_event_loop;
|
||||
|
||||
static TIMER_CALLBACK(timer_handler)
|
||||
{
|
||||
struct event *event = event_create(&g_event_loop, BAR_REFRESH, NULL);
|
||||
event_loop_post(&g_event_loop, event);
|
||||
}
|
||||
|
||||
static SHELL_TIMER_CALLBACK(shell_timer_handler)
|
||||
{
|
||||
struct event *event = event_create(&g_event_loop, SHELL_REFRESH, NULL);
|
||||
event_loop_post(&g_event_loop, event);
|
||||
}
|
||||
|
||||
int bar_manager_get_item_index_for_name(struct bar_manager* bar_manager, char* name) {
|
||||
for (int i = 0; i < bar_manager->bar_item_count; i++) {
|
||||
if (strcmp(bar_manager->bar_items[i]->name, name) == 0) {
|
||||
|
@ -122,6 +136,14 @@ void bar_manager_begin(struct bar_manager *bar_manager)
|
|||
bar_manager->bars[index - 1] = bar_create(did);
|
||||
}
|
||||
}
|
||||
|
||||
int refresh_frequency = 1;
|
||||
int shell_refresh_frequency = 1;
|
||||
bar_manager->refresh_timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + refresh_frequency, refresh_frequency, 0, 0, timer_handler, NULL);
|
||||
bar_manager->shell_refresh_timer = CFRunLoopTimerCreate(NULL, CFAbsoluteTimeGetCurrent() + shell_refresh_frequency, shell_refresh_frequency, 0, 0, shell_timer_handler, NULL);
|
||||
|
||||
CFRunLoopAddTimer(CFRunLoopGetMain(), bar_manager->refresh_timer, kCFRunLoopCommonModes);
|
||||
CFRunLoopAddTimer(CFRunLoopGetMain(), bar_manager->shell_refresh_timer, kCFRunLoopCommonModes);
|
||||
}
|
||||
|
||||
void bar_manager_check_bar_items_for_update_pattern(struct bar_manager* bar_manager, uint32_t pattern) {
|
||||
|
|
|
@ -1,8 +1,16 @@
|
|||
#ifndef BAR_MANAGER_H
|
||||
#define BAR_MANAGER_H
|
||||
#define TIMER_CALLBACK(name) void name(CFRunLoopTimerRef timer, void *context)
|
||||
typedef TIMER_CALLBACK(timer_callback);
|
||||
|
||||
#define SHELL_TIMER_CALLBACK(name) void name(CFRunLoopTimerRef timer, void *context)
|
||||
typedef SHELL_TIMER_CALLBACK(shell_timer_callback);
|
||||
|
||||
|
||||
struct bar_manager
|
||||
{
|
||||
CFRunLoopTimerRef refresh_timer;
|
||||
CFRunLoopTimerRef shell_refresh_timer;
|
||||
struct bar **bars;
|
||||
int bar_count;
|
||||
struct bar_item **bar_items;
|
||||
|
|
Loading…
Reference in a new issue