refactoring of the window logic

This commit is contained in:
Felix Kratz 2022-04-16 17:38:30 +02:00
parent 1d3bb4bd08
commit 932d483aeb
8 changed files with 193 additions and 236 deletions

View file

@ -4,7 +4,7 @@ ODIR = bin
SRC = src
_OBJ = alias.o background.o bar_item.o custom_events.o event.o graph.o \
image.o mouse.o shadow.o text.o message.o mouse.o ax.o bar.o \
image.o mouse.o shadow.o text.o message.o mouse.o ax.o bar.o window.o \
bar_manager.o display.o event_loop.o group.o mach.o popup.o workspace.om
OBJ = $(patsubst %, $(ODIR)/%, $(_OBJ))

141
src/bar.c
View file

@ -3,6 +3,7 @@
#include "event.h"
#include "event_loop.h"
#include "display.h"
#include "window.h"
void bar_draw_graph(struct bar* bar, struct bar_item* bar_item, uint32_t x, bool right_to_left) {
if (!bar_item->has_graph) return;
@ -27,9 +28,9 @@ bool bar_draws_item(struct bar* bar, struct bar_item* bar_item) {
void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* bar_item) {
if (bar->adid != g_bar_manager.active_adid) return;
if (!bar_item->popup.overrides_cell_size)
bar_item->popup.cell_size = bar->frame.size.height;
bar_item->popup.cell_size = bar->window.frame.size.height;
popup_calculate_bounds(&bar_item->popup);
CGPoint anchor = bar->origin;
CGPoint anchor = bar->window.origin;
if (bar_item->popup.align == POSITION_CENTER) {
anchor.x += bar_item->icon.bounds.origin.x
+ bar_item->background.padding_left / 2
@ -44,19 +45,19 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b
- bar_item->popup.background.bounds.size.width;
}
anchor.y += (g_bar_manager.position == POSITION_BOTTOM
? (-bar->frame.size.height
? (-bar->window.frame.size.height
- bar_item->popup.background.bounds.size.height)
: bar->frame.size.height);
: bar->window.frame.size.height);
popup_set_anchor(&bar_item->popup, anchor, bar->adid);
}
void bar_draw(struct bar* bar) {
SLSDisableUpdate(g_connection);
SLSOrderWindow(g_connection, bar->id, -1, 0);
SLSRemoveAllTrackingAreas(g_connection, bar->id);
SLSOrderWindow(g_connection, bar->window.id, -1, 0);
SLSRemoveAllTrackingAreas(g_connection, bar->window.id);
draw_rect(bar->context,
bar->frame,
draw_rect(bar->window.context,
bar->window.frame,
&g_bar_manager.background.color,
g_bar_manager.background.corner_radius,
g_bar_manager.background.border_width,
@ -64,7 +65,7 @@ void bar_draw(struct bar* bar) {
true );
if (g_bar_manager.background.image.enabled) {
image_draw(&g_bar_manager.background.image, bar->context);
image_draw(&g_bar_manager.background.image, bar->window.context);
}
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
@ -80,25 +81,25 @@ void bar_draw(struct bar* bar) {
|| bar_item->update_mask & UPDATE_MOUSE_EXITED) {
CGRect tracking_rect = cgrect_mirror_y(bar_item_construct_bounding_rect(
bar_item),
bar->frame.size.height / 2.);
bar->window.frame.size.height / 2.);
tracking_rect.origin.y -= tracking_rect.size.height;
SLSAddTrackingRect(g_connection, bar->id, tracking_rect);
SLSAddTrackingRect(g_connection, bar->window.id, tracking_rect);
}
bar_item_set_bounding_rect_for_display(bar_item,
bar->adid,
bar->origin,
bar->frame.size.height);
bar->window.origin,
bar->window.frame.size.height);
bar_item_draw(bar_item, bar->context);
bar_item_draw(bar_item, bar->window.context);
if (bar_item->popup.drawing && bar->adid == g_bar_manager.active_adid)
popup_draw(&bar_item->popup);
}
CGContextFlush(bar->context);
SLSOrderWindow(g_connection, bar->id, 1, bar->id);
CGContextFlush(bar->window.context);
SLSOrderWindow(g_connection, bar->window.id, 1, bar->window.id);
SLSReenableUpdate(g_connection);
}
@ -111,21 +112,21 @@ void bar_calculate_bounds(struct bar* bar) {
POSITION_CENTER);
uint32_t bar_left_first_item_x = g_bar_manager.background.padding_left;
uint32_t bar_right_first_item_x = bar->frame.size.width
uint32_t bar_right_first_item_x = bar->window.frame.size.width
- g_bar_manager.background.padding_right;
uint32_t bar_center_first_item_x = (bar->frame.size.width
uint32_t bar_center_first_item_x = (bar->window.frame.size.width
- 2*g_bar_manager.margin
- center_length) / 2 - 1;
uint32_t bar_center_right_first_item_x = (bar->frame.size.width
uint32_t bar_center_right_first_item_x = (bar->window.frame.size.width
+ bar->notch_width) / 2 - 1;
uint32_t bar_center_left_first_item_x = (bar->frame.size.width
uint32_t bar_center_left_first_item_x = (bar->window.frame.size.width
- bar->notch_width) / 2 - 1;
uint32_t* next_position = NULL;
uint32_t y = bar->frame.size.height / 2;
uint32_t y = bar->window.frame.size.height / 2;
for (int i = 0; i < g_bar_manager.bar_item_count; i++) {
struct bar_item* bar_item = g_bar_manager.bar_items[i];
@ -156,7 +157,7 @@ void bar_calculate_bounds(struct bar* bar) {
bar_item->graph.rtl = rtl;
uint32_t bar_item_length = bar_item_calculate_bounds(bar_item,
bar->frame.size.height
bar->window.frame.size.height
- (g_bar_manager.background.border_width + 1),
*next_position,
y );
@ -180,7 +181,7 @@ void bar_calculate_bounds(struct bar* bar) {
}
}
void bar_create_frame(struct bar *bar, CFTypeRef *frame_region) {
CGRect bar_get_frame(struct bar *bar) {
CGRect bounds = display_bounds(bar->did);
bounds.size.width -= 2*g_bar_manager.margin;
CGPoint origin = bounds.origin;
@ -197,105 +198,31 @@ void bar_create_frame(struct bar *bar, CFTypeRef *frame_region) {
origin.y += menu.size.height;
}
bar->frame = (CGRect) {{0, 0},{bounds.size.width,
return (CGRect) {{origin.x, origin.y},{bounds.size.width,
g_bar_manager.background.bounds.size.height}};
bar->origin = origin;
CGSNewRegionWithRect(&bar->frame, frame_region);
}
void bar_resize(struct bar *bar) {
void bar_resize(struct bar* bar) {
if (bar->hidden) return;
CFTypeRef frame_region;
bar_create_frame(bar, &frame_region);
SLSDisableUpdate(g_connection);
SLSOrderWindow(g_connection, bar->id, -1, 0);
SLSSetWindowShape(g_connection,
bar->id,
bar->origin.x,
bar->origin.y,
frame_region );
SLSClearActivationRegion(g_connection, bar->id);
SLSAddActivationRegion(g_connection, bar->id, frame_region);
SLSRemoveAllTrackingAreas(g_connection, bar->id);
window_resize(&bar->window, bar_get_frame(bar));
bar_calculate_bounds(bar);
bar_draw(bar);
SLSOrderWindow(g_connection, bar->id, 1, 0);
SLSReenableUpdate(g_connection);
CFRelease(frame_region);
}
void bar_set_hidden(struct bar* bar, bool hidden) {
if (bar->hidden == hidden) return;
if (hidden) bar_close_window(bar);
if (hidden) window_close(&bar->window);
else bar_create_window(bar);
bar->hidden = hidden;
}
void context_set_font_smoothing(CGContextRef context, bool smoothing) {
CGContextSetAllowsFontSmoothing(context, smoothing);
}
void window_set_blur_radius(uint32_t wid) {
SLSSetWindowBackgroundBlurRadius(g_connection,
wid,
g_bar_manager.blur_radius);
}
void window_disable_shadow(uint32_t wid) {
CFIndex shadow_density = 0;
CFNumberRef shadow_density_cf = CFNumberCreate(kCFAllocatorDefault,
kCFNumberCFIndexType,
&shadow_density );
const void *keys[1] = { CFSTR("com.apple.WindowShadowDensity") };
const void *values[1] = { shadow_density_cf };
CFDictionaryRef shadow_props_cf = CFDictionaryCreate(NULL,
keys,
values,
1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
SLSWindowSetShadowProperties(wid, shadow_props_cf);
CFRelease(shadow_density_cf);
CFRelease(shadow_props_cf);
}
void bar_create_window(struct bar* bar) {
uint64_t set_tags = kCGSStickyTagBit | kCGSHighQualityResamplingTagBit;
uint64_t clear_tags = kCGSSuperStickyTagBit;
window_create(&bar->window, bar_get_frame(bar));
window_set_blur_radius(&bar->window, g_bar_manager.blur_radius);
if (!g_bar_manager.shadow) window_disable_shadow(&bar->window);
CFTypeRef frame_region;
bar_create_frame(bar, &frame_region);
SLSNewWindow(g_connection,
2,
bar->origin.x,
bar->origin.y,
frame_region,
&bar->id );
SLSAddActivationRegion(g_connection, bar->id, frame_region);
CFRelease(frame_region);
SLSSetWindowResolution(g_connection, bar->id, 2.0f);
SLSSetWindowTags(g_connection, bar->id, &set_tags, 64);
SLSClearWindowTags(g_connection, bar->id, &clear_tags, 64);
SLSSetWindowOpacity(g_connection, bar->id, 0);
window_set_blur_radius(bar->id);
if (!g_bar_manager.shadow) window_disable_shadow(bar->id);
SLSSetWindowLevel(g_connection, bar->id, g_bar_manager.window_level);
bar->context = SLWindowContextCreate(g_connection, bar->id, 0);
CGContextSetInterpolationQuality(bar->context, kCGInterpolationNone);
context_set_font_smoothing(bar->context, g_bar_manager.font_smoothing);
}
void bar_close_window(struct bar* bar) {
CGContextRelease(bar->context);
SLSReleaseWindow(g_connection, bar->id);
window_set_level(&bar->window, g_bar_manager.window_level);
context_set_font_smoothing(bar->window.context, g_bar_manager.font_smoothing);
}
struct bar *bar_create(uint32_t did) {
@ -311,6 +238,6 @@ struct bar *bar_create(uint32_t did) {
}
void bar_destroy(struct bar *bar) {
bar_close_window(bar);
window_close(&bar->window);
free(bar);
}

View file

@ -1,32 +1,7 @@
#pragma once
#include "bar_item.h"
#include "misc/helpers.h"
extern CGError SLSDisableUpdate(int cid);
extern CGError SLSReenableUpdate(int cid);
extern CGError SLSNewWindow(int cid, int type, float x, float y, CFTypeRef region, uint32_t *wid);
extern CGError SLSReleaseWindow(int cid, uint32_t wid);
extern CGError SLSSetWindowTags(int cid, uint32_t wid, uint64_t* tags, int tag_size);
extern CGError SLSClearWindowTags(int cid, uint32_t wid, uint64_t* tags, int tag_size);
extern CGError SLSSetWindowShape(int cid, uint32_t wid, float x_offset, float y_offset, CFTypeRef shape);
extern CGError SLSSetWindowResolution(int cid, uint32_t wid, double res);
extern CGError SLSSetWindowOpacity(int cid, uint32_t wid, bool isOpaque);
extern CGError SLSSetWindowBackgroundBlurRadius(int cid, uint32_t wid, uint32_t radius);
extern CGError SLSOrderWindow(int cid, uint32_t wid, int mode, uint32_t relativeToWID);
extern CGError SLSSetWindowLevel(int cid, uint32_t wid, int level);
extern CGContextRef SLWindowContextCreate(int cid, uint32_t wid, CFDictionaryRef options);
extern CGError CGSNewRegionWithRect(CGRect *rect, CFTypeRef *outRegion);
extern CGError SLSAddActivationRegion(uint32_t cid, uint32_t wid, CFTypeRef region);
extern CGError SLSAddTrackingRect(uint32_t cid, uint32_t wid, CGRect rect);
extern CGError SLSClearActivationRegion(uint32_t cid, uint32_t wid);
extern CGError SLSRemoveAllTrackingAreas(uint32_t cid, uint32_t wid);
extern CGError SLSMoveWindow(int cid, uint32_t wid, CGPoint *point);
extern CGError SLSWindowSetShadowProperties(uint32_t wid, CFDictionaryRef properties);
extern int SLSSpaceGetType(int cid, uint64_t sid);
#define kCGSHighQualityResamplingTagBit (1ULL << 4)
#define kCGSStickyTagBit (1ULL << 11)
#define kCGSSuperStickyTagBit (1ULL << 45)
#include "window.h"
#define ALIGN_NONE 0
#define ALIGN_LEFT 1
@ -39,15 +14,12 @@ struct bar {
bool shown;
bool hidden;
uint32_t id;
uint32_t did;
uint32_t sid;
uint32_t adid;
uint32_t notch_width;
CGRect frame;
CGPoint origin;
CGContextRef context;
struct window window;
};
struct bar *bar_create(uint32_t did);
@ -59,8 +31,6 @@ void bar_calculate_bounds(struct bar* bar);
void bar_resize(struct bar* bar);
void bar_draw(struct bar* bar);
void window_set_blur_radius(uint32_t wid);
void window_disable_shadow(uint32_t wid);
bool bar_draws_item(struct bar* bar, struct bar_item* bar_item);
void context_set_font_smoothing(CGContextRef context, bool smoothing);

View file

@ -161,7 +161,7 @@ bool bar_manager_set_background_blur(struct bar_manager* bar_manager, uint32_t r
if (bar_manager->blur_radius == radius) return false;
bar_manager->blur_radius = radius;
for (int i = 0; i < bar_manager->bar_count; i++) {
window_set_blur_radius(bar_manager->bars[i]->id);
window_set_blur_radius(&bar_manager->bars[i]->window, radius);
}
return true;
}
@ -207,7 +207,7 @@ bool bar_manager_set_font_smoothing(struct bar_manager* bar_manager, bool smooth
if (bar_manager->font_smoothing == smoothing) return false;
bar_manager->font_smoothing = smoothing;
for (int i = 0; i < bar_manager->bar_count; i++)
context_set_font_smoothing(bar_manager->bars[i]->context, smoothing);
context_set_font_smoothing(bar_manager->bars[i]->window.context, smoothing);
return true;
}

View file

@ -6,9 +6,6 @@ void popup_init(struct popup* popup) {
popup->drawing = false;
popup->horizontal = false;
popup->overrides_cell_size = false;
popup->context = NULL;
popup->id = 0;
popup->frame.origin = (CGPoint){0,0};
popup->anchor = (CGPoint){0, 0};
popup->y_offset = 0;
popup->adid = 0;
@ -59,68 +56,23 @@ void popup_calculate_bounds(struct popup* popup) {
popup->background.bounds.size.height = y;
}
void popup_create_frame(struct popup *popup, CFTypeRef *frame_region) {
CGSNewRegionWithRect(&popup->background.bounds, frame_region);
}
void popup_resize(struct popup* popup) {
CFTypeRef frame_region;
popup_create_frame(popup, &frame_region);
SLSSetWindowShape(g_connection,
popup->id,
popup->anchor.x,
popup->anchor.y,
frame_region );
SLSClearActivationRegion(g_connection, popup->id);
SLSAddActivationRegion(g_connection, popup->id, frame_region);
SLSRemoveAllTrackingAreas(g_connection, popup->id);
CFRelease(frame_region);
}
void popup_create_window(struct popup* popup) {
uint64_t set_tags = kCGSStickyTagBit | kCGSHighQualityResamplingTagBit;
uint64_t clear_tags = kCGSSuperStickyTagBit;
window_create(&popup->window, (CGRect){{popup->anchor.x, popup->anchor.y},
{popup->background.bounds.size.width,
popup->background.bounds.size.height}});
CFTypeRef frame_region;
popup_create_frame(popup, &frame_region);
if (!popup->background.shadow.enabled)
window_disable_shadow(&popup->window);
SLSNewWindow(g_connection,
2,
popup->anchor.x,
popup->anchor.y,
frame_region,
&popup->id );
SLSAddActivationRegion(g_connection, popup->id, frame_region);
CFRelease(frame_region);
SLSSetWindowResolution(g_connection, popup->id, 2.0f);
SLSSetWindowTags(g_connection, popup->id, &set_tags, 64);
SLSClearWindowTags(g_connection, popup->id, &clear_tags, 64);
SLSSetWindowOpacity(g_connection, popup->id, 0);
SLSSetWindowBackgroundBlurRadius(g_connection,
popup->id,
g_bar_manager.blur_radius);
if (!popup->background.shadow.enabled) window_disable_shadow(popup->id);
SLSSetWindowLevel(g_connection, popup->id, kCGScreenSaverWindowLevelKey);
popup->context = SLWindowContextCreate(g_connection, popup->id, 0);
CGContextSetInterpolationQuality(popup->context, kCGInterpolationNone);
context_set_font_smoothing(popup->context, g_bar_manager.font_smoothing);
window_set_level(&popup->window, kCGScreenSaverWindowLevelKey);
CGContextSetInterpolationQuality(popup->window.context, kCGInterpolationNone);
context_set_font_smoothing(popup->window.context, g_bar_manager.font_smoothing);
popup->drawing = true;
}
void popup_close_window(struct popup* popup) {
CGContextRelease(popup->context);
SLSReleaseWindow(g_connection, popup->id);
popup->context = NULL;
popup->id = false;
window_close(&popup->window);
popup->drawing = false;
}
@ -165,7 +117,7 @@ void popup_set_anchor(struct popup* popup, CGPoint anchor, uint32_t adid) {
|| popup->anchor.y != anchor.y + popup->y_offset) {
popup->anchor = anchor;
popup->anchor.y += popup->y_offset;
SLSMoveWindow(g_connection, popup->id, &popup->anchor);
SLSMoveWindow(g_connection, popup->window.id, &popup->anchor);
}
popup->adid = adid;
}
@ -178,9 +130,11 @@ void popup_set_drawing(struct popup* popup, bool drawing) {
void popup_draw(struct popup* popup) {
if (!popup->drawing) return;
SLSOrderWindow(g_connection, popup->id, -1, 0);
popup_resize(popup);
draw_rect(popup->context,
SLSOrderWindow(g_connection, popup->window.id, -1, 0);
window_resize(&popup->window, (CGRect){{popup->anchor.x, popup->anchor.y},
{popup->background.bounds.size.width,
popup->background.bounds.size.height}});
draw_rect(popup->window.context,
popup->background.bounds,
&popup->background.color,
popup->background.corner_radius,
@ -197,7 +151,7 @@ void popup_draw(struct popup* popup) {
popup->background.bounds.size.height / 2. );
tracking_rect.origin.y -= tracking_rect.size.height;
SLSAddTrackingRect(g_connection, popup->id, tracking_rect);
SLSAddTrackingRect(g_connection, popup->window.id, tracking_rect);
}
bar_item_set_bounding_rect_for_display(bar_item,
@ -207,11 +161,11 @@ void popup_draw(struct popup* popup) {
bool state = bar_item->popup.drawing;
bar_item->popup.drawing = false;
bar_item_draw(bar_item, popup->context);
bar_item_draw(bar_item, popup->window.context);
bar_item->popup.drawing = state;
}
CGContextFlush(popup->context);
SLSOrderWindow(g_connection, popup->id, 1, popup->id);
CGContextFlush(popup->window.context);
SLSOrderWindow(g_connection, popup->window.id, 1, popup->window.id);
}
void popup_destroy(struct popup* popup) {

View file

@ -1,31 +1,7 @@
#pragma once
#include "background.h"
#include "misc/helpers.h"
extern CGError SLSDisableUpdate(int cid);
extern CGError SLSReenableUpdate(int cid);
extern CGError SLSNewWindow(int cid, int type, float x, float y, CFTypeRef region, uint32_t *wid);
extern CGError SLSReleaseWindow(int cid, uint32_t wid);
extern CGError SLSSetWindowTags(int cid, uint32_t wid, uint64_t* tags, int tag_size);
extern CGError SLSClearWindowTags(int cid, uint32_t wid, uint64_t* tags, int tag_size);
extern CGError SLSSetWindowShape(int cid, uint32_t wid, float x_offset, float y_offset, CFTypeRef shape);
extern CGError SLSSetWindowResolution(int cid, uint32_t wid, double res);
extern CGError SLSSetWindowOpacity(int cid, uint32_t wid, bool isOpaque);
extern CGError SLSSetWindowBackgroundBlurRadius(int cid, uint32_t wid, uint32_t radius);
extern CGError SLSOrderWindow(int cid, uint32_t wid, int mode, uint32_t relativeToWID);
extern CGError SLSSetWindowLevel(int cid, uint32_t wid, int level);
extern CGContextRef SLWindowContextCreate(int cid, uint32_t wid, CFDictionaryRef options);
extern CGError CGSNewRegionWithRect(CGRect *rect, CFTypeRef *outRegion);
extern CGError SLSAddActivationRegion(uint32_t cid, uint32_t wid, CFTypeRef region);
extern CGError SLSAddTrackingRect(uint32_t cid, uint32_t wid, CGRect rect);
extern CGError SLSClearActivationRegion(uint32_t cid, uint32_t wid);
extern CGError SLSRemoveAllTrackingAreas(uint32_t cid, uint32_t wid);
extern CGError SLSMoveWindow(int cid, uint32_t wid, CGPoint *point);
extern CGError SLSWindowSetShadowProperties(uint32_t wid, CFDictionaryRef properties);
#define kCGSHighQualityResamplingTagBit (1ULL << 4)
#define kCGSStickyTagBit (1ULL << 11)
#define kCGSSuperStickyTagBit (1ULL << 45)
#include "window.h"
struct bar_item;
@ -36,14 +12,12 @@ struct popup {
char align;
uint32_t id;
uint32_t adid;
uint32_t cell_size;
int y_offset;
CGRect frame;
CGPoint anchor;
CGContextRef context;
struct window window;
struct bar_item** items;
@ -59,7 +33,6 @@ void popup_set_drawing(struct popup* popup, bool drawing);
void popup_remove_item(struct popup* popup, struct bar_item* bar_item);
void popup_calculate_bounds(struct popup* popup);
void popup_resize(struct popup* popup);
void popup_draw(struct popup* popup);
void popup_destroy(struct popup* popup);

88
src/window.c Normal file
View file

@ -0,0 +1,88 @@
#include "window.h"
static CFTypeRef window_create_region(struct window *window, CGRect frame) {
window->frame = (CGRect) {{0, 0},{frame.size.width, frame.size.height}};
window->origin = frame.origin;
CFTypeRef frame_region;
CGSNewRegionWithRect(&window->frame, &frame_region);
return frame_region;
}
void window_create(struct window* window, CGRect frame) {
uint64_t set_tags = kCGSStickyTagBit | kCGSHighQualityResamplingTagBit;
uint64_t clear_tags = kCGSSuperStickyTagBit;
CFTypeRef frame_region = window_create_region(window, frame);
SLSNewWindow(g_connection, 2, window->origin.x, window->origin.y,
frame_region,
&window->id );
SLSAddActivationRegion(g_connection, window->id, frame_region);
CFRelease(frame_region);
SLSSetWindowResolution(g_connection, window->id, 2.0f);
SLSSetWindowTags(g_connection, window->id, &set_tags, 64);
SLSClearWindowTags(g_connection, window->id, &clear_tags, 64);
SLSSetWindowOpacity(g_connection, window->id, 0);
window->context = SLWindowContextCreate(g_connection, window->id, 0);
CGContextSetInterpolationQuality(window->context, kCGInterpolationNone);
}
void window_resize(struct window* window, CGRect frame) {
CFTypeRef frame_region = window_create_region(window, frame);
SLSDisableUpdate(g_connection);
SLSOrderWindow(g_connection, window->id, -1, 0);
SLSSetWindowShape(g_connection,
window->id,
window->origin.x,
window->origin.y,
frame_region );
SLSClearActivationRegion(g_connection, window->id);
SLSAddActivationRegion(g_connection, window->id, frame_region);
SLSRemoveAllTrackingAreas(g_connection, window->id);
SLSOrderWindow(g_connection, window->id, 1, 0);
SLSReenableUpdate(g_connection);
CFRelease(frame_region);
}
void window_close(struct window* window) {
CGContextRelease(window->context);
SLSReleaseWindow(g_connection, window->id);
window->context = NULL;
window->id = 0;
}
void window_set_level(struct window* window, uint32_t level) {
SLSSetWindowLevel(g_connection, window->id, level);
}
void window_set_blur_radius(struct window* window, uint32_t blur_radius) {
SLSSetWindowBackgroundBlurRadius(g_connection, window->id, blur_radius);
}
void context_set_font_smoothing(CGContextRef context, bool smoothing) {
CGContextSetAllowsFontSmoothing(context, smoothing);
}
void window_disable_shadow(struct window* window) {
CFIndex shadow_density = 0;
CFNumberRef shadow_density_cf = CFNumberCreate(kCFAllocatorDefault,
kCFNumberCFIndexType,
&shadow_density );
const void *keys[1] = { CFSTR("com.apple.WindowShadowDensity") };
const void *values[1] = { shadow_density_cf };
CFDictionaryRef shadow_props_cf = CFDictionaryCreate(NULL,
keys,
values,
1,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
SLSWindowSetShadowProperties(window->id, shadow_props_cf);
CFRelease(shadow_density_cf);
CFRelease(shadow_props_cf);
}

45
src/window.h Normal file
View file

@ -0,0 +1,45 @@
#pragma once
#include "misc/helpers.h"
extern CGError SLSDisableUpdate(int cid);
extern CGError SLSReenableUpdate(int cid);
extern CGError SLSNewWindow(int cid, int type, float x, float y, CFTypeRef region, uint32_t *wid);
extern CGError SLSReleaseWindow(int cid, uint32_t wid);
extern CGError SLSSetWindowTags(int cid, uint32_t wid, uint64_t* tags, int tag_size);
extern CGError SLSClearWindowTags(int cid, uint32_t wid, uint64_t* tags, int tag_size);
extern CGError SLSSetWindowShape(int cid, uint32_t wid, float x_offset, float y_offset, CFTypeRef shape);
extern CGError SLSSetWindowResolution(int cid, uint32_t wid, double res);
extern CGError SLSSetWindowOpacity(int cid, uint32_t wid, bool isOpaque);
extern CGError SLSSetWindowBackgroundBlurRadius(int cid, uint32_t wid, uint32_t radius);
extern CGError SLSOrderWindow(int cid, uint32_t wid, int mode, uint32_t relativeToWID);
extern CGError SLSSetWindowLevel(int cid, uint32_t wid, int level);
extern CGContextRef SLWindowContextCreate(int cid, uint32_t wid, CFDictionaryRef options);
extern CGError CGSNewRegionWithRect(CGRect *rect, CFTypeRef *outRegion);
extern CGError SLSAddActivationRegion(uint32_t cid, uint32_t wid, CFTypeRef region);
extern CGError SLSAddTrackingRect(uint32_t cid, uint32_t wid, CGRect rect);
extern CGError SLSClearActivationRegion(uint32_t cid, uint32_t wid);
extern CGError SLSRemoveAllTrackingAreas(uint32_t cid, uint32_t wid);
extern CGError SLSMoveWindow(int cid, uint32_t wid, CGPoint *point);
extern CGError SLSWindowSetShadowProperties(uint32_t wid, CFDictionaryRef properties);
extern int SLSSpaceGetType(int cid, uint64_t sid);
#define kCGSHighQualityResamplingTagBit (1ULL << 4)
#define kCGSStickyTagBit (1ULL << 11)
#define kCGSSuperStickyTagBit (1ULL << 45)
struct window {
uint32_t id;
CGRect frame;
CGPoint origin;
CGContextRef context;
};
void window_create(struct window* window, CGRect frame);
void window_close(struct window* window);
void window_resize(struct window* window, CGRect frame);
void window_set_blur_radius(struct window* window, uint32_t blur_radius);
void window_disable_shadow(struct window* window);
void window_set_level(struct window* window, uint32_t level);
void context_set_font_smoothing(CGContextRef context, bool smoothing);