Skip to content

Commit

Permalink
Fix SIGSEGV with XWayland applications
Browse files Browse the repository at this point in the history
Application id can be null for XWayland apps.
Resolves #10.

Signed-off-by: Artem Senichev <[email protected]>
  • Loading branch information
artemsen committed Oct 23, 2023
1 parent be6a72b commit 0ec2186
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ static int on_focus_change(int wnd_id, const char* app_id, const char* title)
uint32_t tab_id = 0;

// generate unique tab id from window title (if it is a browser)
for (size_t i = 0; i < tab_apps_num; ++i) {
if (strcmp(app_id, tab_apps_list[i]) == 0) {
const char* ptr = title;
// djb2 hash
tab_id = 5381;
while (*ptr) {
tab_id = ((tab_id << 5) + tab_id) + *ptr++;
if (app_id && title) {
for (size_t i = 0; i < tab_apps_num; ++i) {
if (strcmp(app_id, tab_apps_list[i]) == 0) {
const char* ptr = title;
// djb2 hash
tab_id = 5381;
while (*ptr) {
tab_id = ((tab_id << 5) + tab_id) + *ptr++;
}
break;
}
break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/sway.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ int sway_monitor(on_focus fn_focus, on_title fn_title,
struct json_object* event_node;
if (json_object_object_get_ex(msg, "change", &event_node)) {
int wnd_id = -1;
const char* app_id = "";
const char* title = "";
const char* app_id = NULL;
const char* title = NULL;
const char* event_name = json_object_get_string(event_node);
if (strcmp(event_name, "focus") == 0) {
container_info(msg, &wnd_id, &app_id, &title);
Expand Down

0 comments on commit 0ec2186

Please sign in to comment.