Skip to content

Commit 0ec2186

Browse files
committed
Fix SIGSEGV with XWayland applications
Application id can be null for XWayland apps. Resolves #10. Signed-off-by: Artem Senichev <artemsen@gmail.com>
1 parent be6a72b commit 0ec2186

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/main.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ static int on_focus_change(int wnd_id, const char* app_id, const char* title)
4545
uint32_t tab_id = 0;
4646

4747
// generate unique tab id from window title (if it is a browser)
48-
for (size_t i = 0; i < tab_apps_num; ++i) {
49-
if (strcmp(app_id, tab_apps_list[i]) == 0) {
50-
const char* ptr = title;
51-
// djb2 hash
52-
tab_id = 5381;
53-
while (*ptr) {
54-
tab_id = ((tab_id << 5) + tab_id) + *ptr++;
48+
if (app_id && title) {
49+
for (size_t i = 0; i < tab_apps_num; ++i) {
50+
if (strcmp(app_id, tab_apps_list[i]) == 0) {
51+
const char* ptr = title;
52+
// djb2 hash
53+
tab_id = 5381;
54+
while (*ptr) {
55+
tab_id = ((tab_id << 5) + tab_id) + *ptr++;
56+
}
57+
break;
5558
}
56-
break;
5759
}
5860
}
5961

src/sway.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ int sway_monitor(on_focus fn_focus, on_title fn_title,
283283
struct json_object* event_node;
284284
if (json_object_object_get_ex(msg, "change", &event_node)) {
285285
int wnd_id = -1;
286-
const char* app_id = "";
287-
const char* title = "";
286+
const char* app_id = NULL;
287+
const char* title = NULL;
288288
const char* event_name = json_object_get_string(event_node);
289289
if (strcmp(event_name, "focus") == 0) {
290290
container_info(msg, &wnd_id, &app_id, &title);

0 commit comments

Comments
 (0)