forked from koekeishiya/yabai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
koekeishiya#565 re-introduce a more efficient window border system
- Loading branch information
1 parent
b0fbe08
commit 8d79e2a
Showing
21 changed files
with
2,616 additions
and
1,893 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include "border.h" | ||
|
||
extern struct window_manager g_window_manager; | ||
|
||
void border_redraw(struct window *window) | ||
{ | ||
SLSDisableUpdate(g_connection); | ||
CGContextClearRect(window->border.context, window->border.frame); | ||
CGContextAddPath(window->border.context, window->border.path); | ||
CGContextStrokePath(window->border.context); | ||
CGContextFlush(window->border.context); | ||
SLSReenableUpdate(g_connection); | ||
} | ||
|
||
void border_activate(struct window *window) | ||
{ | ||
if (!window->border.id) return; | ||
|
||
CGContextSetRGBStrokeColor(window->border.context, | ||
g_window_manager.active_border_color.r, | ||
g_window_manager.active_border_color.g, | ||
g_window_manager.active_border_color.b, | ||
g_window_manager.active_border_color.a); | ||
border_redraw(window); | ||
} | ||
|
||
void border_deactivate(struct window *window) | ||
{ | ||
if (!window->border.id) return; | ||
|
||
CGContextSetRGBStrokeColor(window->border.context, | ||
g_window_manager.normal_border_color.r, | ||
g_window_manager.normal_border_color.g, | ||
g_window_manager.normal_border_color.b, | ||
g_window_manager.normal_border_color.a); | ||
border_redraw(window); | ||
} | ||
|
||
void border_show(struct window *window) | ||
{ | ||
if (window->border.id) SLSOrderWindow(g_connection, window->border.id, 1, window->id); | ||
} | ||
|
||
void border_hide(struct window *window) | ||
{ | ||
if (window->border.id) SLSOrderWindow(g_connection, window->border.id, 0, window->id); | ||
} | ||
|
||
void border_create(struct window *window) | ||
{ | ||
if (!g_window_manager.enable_window_border) return; | ||
if (window->border.id) return; | ||
|
||
window->border.frame = window_ax_frame(window); | ||
if (window->border.region) CFRelease(window->border.region); | ||
CGSNewRegionWithRect(&window->border.frame, &window->border.region); | ||
window->border.frame.origin.x = 0; | ||
window->border.frame.origin.y = 0; | ||
|
||
uint64_t tags[2] = { (1ULL << 31) | kCGSIgnoreForExposeTagBit | kCGSIgnoreForEventsTagBit, 0 }; | ||
SLSNewWindow(g_connection, 2, 0, 0, window->border.region, &window->border.id); | ||
SLSSetWindowTags(g_connection, window->border.id, tags, 64); | ||
SLSSetWindowResolution(g_connection, window->border.id, 1.0f); | ||
SLSSetWindowOpacity(g_connection, window->border.id, 0); | ||
SLSSetWindowLevel(g_connection, window->border.id, window_level(window)); | ||
window->border.context = SLWindowContextCreate(g_connection, window->border.id, 0); | ||
CGContextSetLineWidth(window->border.context, g_window_manager.border_width); | ||
CGContextSetRGBStrokeColor(window->border.context, | ||
g_window_manager.normal_border_color.r, | ||
g_window_manager.normal_border_color.g, | ||
g_window_manager.normal_border_color.b, | ||
g_window_manager.normal_border_color.a); | ||
window_manager_add_to_window_group(window->border.id, window->id); | ||
} | ||
|
||
void border_resize(struct window *window) | ||
{ | ||
if (!window->border.id) return; | ||
|
||
window->border.frame = window_ax_frame(window); | ||
if (window->border.region) CFRelease(window->border.region); | ||
CGSNewRegionWithRect(&window->border.frame, &window->border.region); | ||
window->border.frame.origin.x = 0; | ||
window->border.frame.origin.y = 0; | ||
|
||
if (window->border.path) CGPathRelease(window->border.path); | ||
window->border.path = CGPathCreateMutable(); | ||
CGPathAddRoundedRect(window->border.path, NULL, window->border.frame, 0, 0); | ||
|
||
SLSDisableUpdate(g_connection); | ||
SLSSetWindowShape(g_connection, window->border.id, 0.0f, 0.0f, window->border.region); | ||
CGContextClearRect(window->border.context, window->border.frame); | ||
CGContextAddPath(window->border.context, window->border.path); | ||
CGContextStrokePath(window->border.context); | ||
CGContextFlush(window->border.context); | ||
SLSReenableUpdate(g_connection); | ||
} | ||
|
||
void border_destroy(struct window *window) | ||
{ | ||
if (!window->border.id) return; | ||
|
||
if (window->border.region) CFRelease(window->border.region); | ||
if (window->border.path) CGPathRelease(window->border.path); | ||
CGContextRelease(window->border.context); | ||
SLSReleaseWindow(g_connection, window->border.id); | ||
memset(&window->border, 0, sizeof(struct border)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef BORDER_H | ||
#define BORDER_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[2], int tag_size); | ||
extern CGError SLSSetWindowShape(int cid, uint32_t wid, float x_offset, float y_offset, CFTypeRef shape); | ||
extern CGError SLSSetWindowOpacity(int cid, uint32_t wid, bool isOpaque); | ||
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); | ||
|
||
#define kCGSIgnoreForExposeTagBit (1 << 7) | ||
#define kCGSIgnoreForEventsTagBit (1 << 9) | ||
|
||
struct border | ||
{ | ||
uint32_t id; | ||
CGContextRef context; | ||
CFTypeRef region; | ||
CGRect frame; | ||
CGMutablePathRef path; | ||
}; | ||
|
||
struct window; | ||
void border_redraw(struct window *window); | ||
void border_activate(struct window *window); | ||
void border_deactivate(struct window *window); | ||
void border_show(struct window *window); | ||
void border_hide(struct window *window); | ||
void border_create(struct window *window); | ||
void border_resize(struct window *window); | ||
void border_destroy(struct window *window); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.