Skip to content

Commit

Permalink
Fix #7
Browse files Browse the repository at this point in the history
  • Loading branch information
xiamaz committed Nov 12, 2022
1 parent 357ac5c commit edbcc9d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

## Installation

If you don't have yabai, install yabai (version 4.0.0 required) first: [Official installation guide](https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release))
If you don't have yabai, install yabai (version 4.0.2 required) first: [Official installation guide](https://github.com/koekeishiya/yabai/wiki/Installing-yabai-(latest-release))

Just download and unzip the latest release of YabaiIndicator from [Releases](https://github.com/xiamaz/YabaiIndicator/releases) and run. Now you should be able to see empty spaces for each desktop and clicking spaces should work.

Expand All @@ -48,14 +48,6 @@ yabai -m signal --add event=window_minimized action='echo "refresh windows" | nc
yabai -m signal --add event=window_deminimized action='echo "refresh windows" | nc -U /tmp/yabai-indicator.socket'
```

## How it works

Information on spaces and displays is directly taken from SkyLight API and space and display switches are handled through the NotificationCenter. Unfortunately that is not enough to ensure that the information on the space indicator is correct, as MissionControl can be used to Add/Delete/Reorder spaces. Fortunately MissionControl invocation can be caught via the Accessibility API, as is done by Yabai.

IPC with easy shell scripting is realized through a UNIX Domain Socket Server, that listens at `/tmp/yabai-indicator.socket`. Currently only a `refresh` message is implemented, which is used to allow yabai signals to modify our UI.

The Menubar Indicator uses SwiftUI and is integrated into the StatusBarItem as a Subview of the default button. While replacing the StatusBarItem view is being deprecated, this approach should be future-proof for now.

If certain keybinds modify the spaces arrangement the following commands needs to be added to keep the indicator in sync:

```
Expand Down
4 changes: 2 additions & 2 deletions YabaiIndicator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.3.1;
MARKETING_VERSION = 0.3.2;
PRODUCT_BUNDLE_IDENTIFIER = de.arsbrevis.YabaiIndicator;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -567,7 +567,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.3.1;
MARKETING_VERSION = 0.3.2;
PRODUCT_BUNDLE_IDENTIFIER = de.arsbrevis.YabaiIndicator;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
16 changes: 12 additions & 4 deletions YabaiIndicator/SocketClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <sys/un.h>
#include <sys/socket.h>

#define MAXLEN 256
#define MAXLEN 512
#define SOCKET_PATH_FMT "/tmp/yabai_%s.socket"
#define FAILURE_MESSAGE "\x07"

Expand Down Expand Up @@ -60,8 +60,10 @@ int send_message(int argc, char** argv, char** response) {
message_length += argl[i];
}

char *message = malloc(message_length);
char *temp = message;
char *message = malloc(sizeof(int)+message_length);
char *temp = sizeof(int)+message;

memcpy(message, &message_length, sizeof(int));

for (int i = 1; i < argc; ++i) {
memcpy(temp, argv[i], argl[i]);
Expand All @@ -71,6 +73,12 @@ int send_message(int argc, char** argv, char** response) {
*temp++ = '\0';

int sockfd;
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sockfd == -1) {
snprintf(*response, BUFSIZ, "yabai-msg: failed to open socket..\n");
return EXIT_FAILURE;
}

char socket_file[MAXLEN];
snprintf(socket_file, sizeof(socket_file), SOCKET_PATH_FMT, user);

Expand All @@ -79,7 +87,7 @@ int send_message(int argc, char** argv, char** response) {
return EXIT_FAILURE;
}

if (send(sockfd, message, message_length, 0) == -1) {
if (send(sockfd, message, sizeof(int)+message_length, 0) == -1) {
snprintf(*response, BUFSIZ, "yabai-msg: failed to send data..\n");
return EXIT_FAILURE;
}
Expand Down

0 comments on commit edbcc9d

Please sign in to comment.