specify window owner and name for window aliasing

This commit is contained in:
FelixKratz 2021-09-20 00:27:12 +02:00
parent 08d6227c19
commit a099235741
4 changed files with 31 additions and 8 deletions

View file

@ -401,6 +401,17 @@ this operation requires screen capture permissions, which should be granted in t
This will put the default item into sketchybar.
Aliases currently are not clickable.
The command can be overloaded by providing a *window_owner* and a *window_name*
```bash
sketchybar -m add alias <window_owner>,<window_name> <position>
```
this way the default system items can also be slurped into sketchybar, e.g.:
Owner: Control Center, Name: Bluetooth <br>
Owner: Control Center, Name: WiFi <br>
Owner: Control Center, Name: UserSwitcher <br>
Owner: TextInputSwitcher, Name: Keyboard Input <br>
Owner: SystemUIServer, Name: AppleTimeMachineExtra <br>
## Credits
yabai,
spacebar,

View file

@ -6,9 +6,10 @@ void alias_get_permission(struct alias* alias) {
if (@available(macOS 10.15, *)) alias->permission = CGRequestScreenCaptureAccess();
}
void alias_init(struct alias* alias, char* name) {
void alias_init(struct alias* alias, char* owner, char* name) {
alias->using_light_colors = true;
alias->name = name;
alias->owner = owner;
alias->wid = 0;
alias->image_ref = NULL;
alias_get_permission(alias);
@ -28,10 +29,12 @@ void alias_find_window(struct alias* alias) {
if (!name_ref) continue;
if (!owner_ref) continue;
char* owner = cfstring_copy(owner_ref);
char* name = cfstring_copy(name_ref);
if (!owner) continue;
if (strcmp(alias->name, owner) != 0) { free(owner); continue; }
if (!(alias->owner && strcmp(alias->owner, owner) == 0 && ((alias->name && strcmp(alias->name, name) == 0) || !alias->name))) { free(owner); free(name); continue; }
free(owner);
free(name);
CFNumberRef layer_ref = CFDictionaryGetValue(dictionary, kCGWindowLayer);
if (!layer_ref) continue;

View file

@ -7,12 +7,13 @@ struct alias {
bool using_light_colors;
bool permission;
char* name;
char* owner;
uint32_t wid;
CGImageRef image_ref;
CGPoint size;
};
void alias_init(struct alias* alias, char* name);
void alias_init(struct alias* alias, char* owner, char* name);
bool alias_update_image(struct alias* alias);
void alias_find_window(struct alias* alias);

View file

@ -1,6 +1,8 @@
#include "message.h"
#include "alias.h"
#include "bar_item.h"
#include "bar_manager.h"
#include "misc/helpers.h"
#include <_types/_uint32_t.h>
#include <string.h>
@ -160,15 +162,15 @@ static struct token get_token(char **message) {
return token;
}
static void get_key_value_pair(char *token, char **key, char **value) {
static void get_key_value_pair(char *token, char **key, char **value, char split) {
*key = token;
while (*token) {
if (token[0] == '=') break;
if (token[0] == split) break;
++token;
}
if (*token != '=') {
if (*token != split) {
*key = NULL;
*value = NULL;
} else if (token[1]) {
@ -315,7 +317,13 @@ static void handle_domain_add(FILE* rsp, struct token domain, char* message) {
bar_item->update_mask |= UPDATE_SPACE_CHANGE;
}
else if (bar_item->type == BAR_COMPONENT_ALIAS) {
alias_init(&bar_item->alias, token_to_string(name));
char* owner = NULL;
char* nme = NULL;
get_key_value_pair(name.text, &owner, &nme, ',');
if (!nme || !owner)
alias_init(&bar_item->alias, token_to_string(name), NULL);
else
alias_init(&bar_item->alias, string_copy(owner), string_copy(nme));
bar_item->has_alias = true;
}
} else if (token_equals(command, COMMAND_ADD_PLUGIN)) {
@ -518,7 +526,7 @@ static void handle_domain_config(FILE *rsp, struct token domain, char *message)
static char* reformat_batch_key_value_pair(struct token token) {
char* key = NULL;
char* value = NULL;
get_key_value_pair(token.text, &key, &value);
get_key_value_pair(token.text, &key, &value, '=');
if (!key) return NULL;
char* rbr_msg = malloc((strlen(key) + (value ? strlen(value) : 0) + 3) * sizeof(char));
pack_key_value_pair(rbr_msg, key, value);