Skip to content

Commit

Permalink
#68 experimenting with AXTabGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Jul 1, 2019
1 parent d263fa2 commit fa53a84
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 48 deletions.
7 changes: 7 additions & 0 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ static OBSERVER_CALLBACK(application_notification_handler)
struct event *event;
event_create(event, WINDOW_FOCUSED, (void *)(intptr_t) window_id);
event_loop_post(&g_event_loop, event);
} else if (CFEqual(notification, kAXMainWindowChangedNotification)) {
uint32_t window_id = ax_window_id(element);
if (!window_id) return;

struct event *event;
event_create(event, WINDOW_MAIN_CHANGED, (void *)(intptr_t) window_id);
event_loop_post(&g_event_loop, event);
} else if (CFEqual(notification, kAXWindowMovedNotification)) {
uint32_t window_id = ax_window_id(element);
if (!window_id) return;
Expand Down
14 changes: 8 additions & 6 deletions src/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@ typedef OBSERVER_CALLBACK(observer_callback);

#define AX_APPLICATION_WINDOW_CREATED_INDEX 0
#define AX_APPLICATION_WINDOW_FOCUSED_INDEX 1
#define AX_APPLICATION_WINDOW_MOVED_INDEX 2
#define AX_APPLICATION_WINDOW_RESIZED_INDEX 3
#define AX_APPLICATION_WINDOW_TITLE_CHANGED_INDEX 4
#define AX_APPLICATION_WINDOW_MENU_OPENED_INDEX 5
#define AX_APPLICATION_WINDOW_MAIN_CHANGED_INDEX 2
#define AX_APPLICATION_WINDOW_MOVED_INDEX 3
#define AX_APPLICATION_WINDOW_RESIZED_INDEX 4
#define AX_APPLICATION_WINDOW_TITLE_CHANGED_INDEX 5
#define AX_APPLICATION_WINDOW_MENU_OPENED_INDEX 6

#define AX_APPLICATION_WINDOW_CREATED (1 << AX_APPLICATION_WINDOW_CREATED_INDEX)
#define AX_APPLICATION_WINDOW_FOCUSED (1 << AX_APPLICATION_WINDOW_FOCUSED_INDEX)
#define AX_APPLICATION_WINDOW_MAIN_CHANGED (1 << AX_APPLICATION_WINDOW_MAIN_CHANGED_INDEX)
#define AX_APPLICATION_WINDOW_MOVED (1 << AX_APPLICATION_WINDOW_MOVED_INDEX)
#define AX_APPLICATION_WINDOW_RESIZED (1 << AX_APPLICATION_WINDOW_RESIZED_INDEX)
#define AX_APPLICATION_WINDOW_TITLE_CHANGED (1 << AX_APPLICATION_WINDOW_TITLE_CHANGED_INDEX)
#define AX_APPLICATION_ALL (AX_APPLICATION_WINDOW_CREATED |\
AX_APPLICATION_WINDOW_FOCUSED |\
AX_APPLICATION_WINDOW_MAIN_CHANGED |\
AX_APPLICATION_WINDOW_MOVED |\
AX_APPLICATION_WINDOW_RESIZED |\
AX_APPLICATION_WINDOW_TITLE_CHANGED)

static const CFStringRef kAXFocusedTabChangedNotification = CFSTR("AXFocusedTabChanged");

static CFStringRef ax_application_notification[] =
{
[AX_APPLICATION_WINDOW_CREATED_INDEX] = kAXCreatedNotification,
[AX_APPLICATION_WINDOW_FOCUSED_INDEX] = kAXFocusedWindowChangedNotification,
[AX_APPLICATION_WINDOW_MAIN_CHANGED_INDEX] = kAXMainWindowChangedNotification,
[AX_APPLICATION_WINDOW_MOVED_INDEX] = kAXWindowMovedNotification,
[AX_APPLICATION_WINDOW_RESIZED_INDEX] = kAXWindowResizedNotification,
[AX_APPLICATION_WINDOW_TITLE_CHANGED_INDEX] = kAXTitleChangedNotification,
Expand Down
153 changes: 129 additions & 24 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ static EVENT_CALLBACK(EVENT_HANDLER_APPLICATION_LAUNCHED)
for (int i = 0; i < window_count; ++i) {
struct ax_window *window = window_list[i];
if (window) {
struct window_group *group = window_manager_find_grouped_window(&g_window_manager, window->id);
if (group && group->active_window_id != window->id) continue;

if (window_manager_should_manage_window(window)) {
struct view *view = space_manager_tile_window_on_space_with_insertion_point(&g_space_manager, window, window_space(window), prev_window_id);
window_manager_add_managed_window(&g_window_manager, window, view);
Expand Down Expand Up @@ -236,7 +239,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_APPLICATION_TERMINATED)
struct ax_window *window = window_list[i];
if (!window) continue;

struct view *view = window_manager_find_managed_window(&g_window_manager, window);
struct view *view = window_manager_find_managed_window(&g_window_manager, window->id);
if (view) {
space_manager_untile_window(&g_space_manager, view, window);
window_manager_remove_managed_window(&g_window_manager, window->id);
Expand Down Expand Up @@ -363,6 +366,9 @@ static EVENT_CALLBACK(EVENT_HANDLER_APPLICATION_VISIBLE)
for (int i = 0; i < window_count; ++i) {
struct ax_window *window = window_list[i];
if (window) {
struct window_group *group = window_manager_find_grouped_window(&g_window_manager, window->id);
if (group && group->active_window_id != window->id) continue;

if (window_manager_should_manage_window(window)) {
struct view *view = space_manager_tile_window_on_space_with_insertion_point(&g_space_manager, window, window_space(window), prev_window_id);
window_manager_add_managed_window(&g_window_manager, window, view);
Expand Down Expand Up @@ -396,7 +402,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_APPLICATION_HIDDEN)

border_window_hide(window);

struct view *view = window_manager_find_managed_window(&g_window_manager, window);
struct view *view = window_manager_find_managed_window(&g_window_manager, window->id);
if (view) {
space_manager_untile_window(&g_space_manager, view, window);
window_manager_remove_managed_window(&g_window_manager, window->id);
Expand All @@ -423,6 +429,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_CREATED)
if (!application) return EVENT_FAILURE;

struct ax_window *window = window_create(application, CFRetain(context), window_id);
window_manager_populate_window_group(&g_window_manager, window);
window_manager_apply_rules_to_window(&g_space_manager, &g_window_manager, window);
window_manager_set_window_opacity(&g_window_manager, window, g_window_manager.normal_window_opacity);
window_manager_purify_window(&g_window_manager, window);
Expand All @@ -445,16 +452,23 @@ static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_CREATED)
}
}

if (window_manager_should_manage_window(window)) {
struct view *view = space_manager_tile_window_on_space(&g_space_manager, window, window_space(window));
window_manager_add_managed_window(&g_window_manager, window, view);
}

if (window_manager_find_lost_focused_event(&g_window_manager, window->id)) {
struct window_group *group = window_manager_find_grouped_window(&g_window_manager, window->id);
if (group) {
struct event *event;
event_create(event, WINDOW_FOCUSED, (void *)(intptr_t) window->id);
event_create(event, WINDOW_MAIN_CHANGED, (void *)(intptr_t) window->id);
event_loop_post(&g_event_loop, event);
window_manager_remove_lost_focused_event(&g_window_manager, window->id);
} else {
if (window_manager_should_manage_window(window)) {
struct view *view = space_manager_tile_window_on_space(&g_space_manager, window, window_space(window));
window_manager_add_managed_window(&g_window_manager, window, view);
}

if (window_manager_find_lost_focused_event(&g_window_manager, window->id)) {
struct event *event;
event_create(event, WINDOW_FOCUSED, (void *)(intptr_t) window->id);
event_loop_post(&g_event_loop, event);
window_manager_remove_lost_focused_event(&g_window_manager, window->id);
}
}
} else {
debug("%s: could not observe %s %d\n", __FUNCTION__, window->application->name, window->id);
Expand All @@ -480,11 +494,37 @@ static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_DESTROYED)

if (g_mouse_state.window == window) g_mouse_state.window = NULL;

struct view *view = window_manager_find_managed_window(&g_window_manager, window);
if (view) {
space_manager_untile_window(&g_space_manager, view, window);
window_manager_remove_managed_window(&g_window_manager, window->id);
window_manager_purify_window(&g_window_manager, window);
struct window_group *group = window_manager_find_grouped_window(&g_window_manager, window->id);
if (group) {
window_group_remove_window(group, window->id);
window_manager_remove_grouped_window(&g_window_manager, window->id);

uint32_t new_wid = (buf_len(group->window_list) == 1) ? group->window_list[0] : window_group_find_active_window(group);
struct ax_window *new_window = window_manager_find_window(&g_window_manager, new_wid);
assert(new_window);

struct view *view = window_manager_find_managed_window(&g_window_manager, group->active_window_id);
if (view) {
window_manager_remove_managed_window(&g_window_manager, group->active_window_id);
window_manager_add_managed_window(&g_window_manager, new_window, view);
struct window_node *node = view_find_window_node(view->root, group->active_window_id);
node->window_id = new_window->id;
}

if (buf_len(group->window_list) == 1) {
window_group_remove_window(group, new_window->id);
window_manager_remove_grouped_window(&g_window_manager, new_window->id);
window_group_destroy(group);
} else {
group->active_window_id = new_window->id;
}
} else {
struct view *view = window_manager_find_managed_window(&g_window_manager, window->id);
if (view) {
space_manager_untile_window(&g_space_manager, view, window);
window_manager_remove_managed_window(&g_window_manager, window->id);
window_manager_purify_window(&g_window_manager, window);
}
}

return EVENT_SUCCESS;
Expand Down Expand Up @@ -543,6 +583,65 @@ static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_FOCUSED)
return EVENT_SUCCESS;
}

static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_MAIN_CHANGED)
{
uint32_t window_id = (uint32_t)(intptr_t) context;
struct ax_window *window = window_manager_find_window(&g_window_manager, window_id);
if (!window) return EVENT_FAILURE;

if (!__sync_bool_compare_and_swap(window->id_ptr, &window->id, &window->id)) {
debug("%s: %d has been marked invalid by the system, ignoring event..\n", __FUNCTION__, window_id);
return EVENT_SUCCESS;
}

if (window_manager_find_lost_focused_event(&g_window_manager, window->id)) {
return EVENT_FAILURE;
}

struct window_group *group = window_manager_find_grouped_window(&g_window_manager, window->id);
if (!group) return EVENT_FAILURE;

printf("%s: %s %d\n", __FUNCTION__, window->application->name, window->id);
struct ax_window *active_window = window_manager_find_window(&g_window_manager, group->active_window_id);
assert(active_window);

if (active_window == window) {
struct ax_window *focused_window = window_manager_find_window(&g_window_manager, g_window_manager.focused_window_id);
if (focused_window && focused_window != window) {
border_window_deactivate(focused_window);
window_manager_set_window_opacity(&g_window_manager, focused_window, g_window_manager.normal_window_opacity);
}
} else {
border_window_deactivate(active_window);
border_window_hide(active_window);
window_manager_set_window_opacity(&g_window_manager, active_window, g_window_manager.normal_window_opacity);

struct view *view = window_manager_find_managed_window(&g_window_manager, group->active_window_id);
if (view) {
window_manager_remove_managed_window(&g_window_manager, group->active_window_id);
window_manager_add_managed_window(&g_window_manager, window, view);
struct window_node *node = view_find_window_node(view->root, group->active_window_id);
node->window_id = window->id;
}

group->active_window_id = window->id;
}

g_window_manager.focused_window_id = window->id;
g_window_manager.focused_window_psn = window->application->psn;

border_window_activate(window);
window_manager_set_window_opacity(&g_window_manager, window, g_window_manager.active_window_opacity);

if (g_mouse_state.ffm_window_id != window->id) {
window_manager_center_mouse(&g_window_manager, window);
} else {
g_mouse_state.ffm_window_id = 0;
}

return EVENT_SUCCESS;
}

static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_MOVED)
{
uint32_t window_id = (uint32_t)(intptr_t) context;
Expand All @@ -559,7 +658,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_MOVED)
debug("%s: %s %d\n", __FUNCTION__, window->application->name, window->id);

#if 0
struct view *view = window_manager_find_managed_window(&g_window_manager, window);
struct view *view = window_manager_find_managed_window(&g_window_manager, window->id);
if (view) view_flush(view);
#endif

Expand All @@ -584,7 +683,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_RESIZED)
debug("%s: %s %d\n", __FUNCTION__, window->application->name, window->id);

#if 0
struct view *view = window_manager_find_managed_window(&g_window_manager, window);
struct view *view = window_manager_find_managed_window(&g_window_manager, window->id);
if (view) view_flush(view);
#endif

Expand Down Expand Up @@ -612,7 +711,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_MINIMIZED)
g_window_manager.last_window_id = g_window_manager.focused_window_id;
}

struct view *view = window_manager_find_managed_window(&g_window_manager, window);
struct view *view = window_manager_find_managed_window(&g_window_manager, window->id);
if (view) {
space_manager_untile_window(&g_space_manager, view, window);
window_manager_remove_managed_window(&g_window_manager, window->id);
Expand All @@ -635,6 +734,10 @@ static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_DEMINIMIZED)
}

window->is_minimized = false;

struct window_group *group = window_manager_find_grouped_window(&g_window_manager, window_id);
if (group && group->active_window_id != window_id) return EVENT_FAILURE;

border_window_show(window);

if (space_manager_is_window_on_active_space(window)) {
Expand Down Expand Up @@ -831,7 +934,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_UP)
return EVENT_SUCCESS;
}

struct view *view = window_manager_find_managed_window(&g_window_manager, g_mouse_state.window);
struct view *view = window_manager_find_managed_window(&g_window_manager, g_mouse_state.window->id);

if ((g_mouse_state.current_action != MOUSE_MODE_RESIZE) && (view && view->layout == VIEW_BSP)) {
CGRect frame = window_ax_frame(g_mouse_state.window);
Expand Down Expand Up @@ -1049,12 +1152,14 @@ static EVENT_CALLBACK(EVENT_HANDLER_MISSION_CONTROL_EXIT)
while (bucket) {
if (bucket->value) {
struct ax_window *window = bucket->value;
if ((!window->application->is_hidden) &&
(!window->is_minimized)) {
border_window_show(window);
}
}
if (window->application->is_hidden || window->is_minimized) goto next;

struct window_group *group = window_manager_find_grouped_window(&g_window_manager, window->id);
if (group && group->active_window_id != window->id) goto next;

border_window_show(window);
}
next:
bucket = bucket->next;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_APPLICATION_HIDDEN);
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_CREATED);
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_DESTROYED);
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_FOCUSED);
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_MAIN_CHANGED);
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_MOVED);
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_RESIZED);
static EVENT_CALLBACK(EVENT_HANDLER_WINDOW_MINIMIZED);
Expand Down Expand Up @@ -61,6 +62,7 @@ enum event_type
WINDOW_CREATED,
WINDOW_DESTROYED,
WINDOW_FOCUSED,
WINDOW_MAIN_CHANGED,
WINDOW_MOVED,
WINDOW_RESIZED,
WINDOW_MINIMIZED,
Expand Down Expand Up @@ -103,6 +105,7 @@ static const char *event_type_str[] =
[WINDOW_CREATED] = "window_created",
[WINDOW_DESTROYED] = "window_destroyed",
[WINDOW_FOCUSED] = "window_focused",
[WINDOW_MAIN_CHANGED] = "window_main_changed",
[WINDOW_MOVED] = "window_moved",
[WINDOW_RESIZED] = "window_resized",
[WINDOW_MINIMIZED] = "window_minimized",
Expand Down Expand Up @@ -143,6 +146,7 @@ static event_callback *event_handler[] =
[WINDOW_CREATED] = EVENT_HANDLER_WINDOW_CREATED,
[WINDOW_DESTROYED] = EVENT_HANDLER_WINDOW_DESTROYED,
[WINDOW_FOCUSED] = EVENT_HANDLER_WINDOW_FOCUSED,
[WINDOW_MAIN_CHANGED] = EVENT_HANDLER_WINDOW_MAIN_CHANGED,
[WINDOW_MOVED] = EVENT_HANDLER_WINDOW_MOVED,
[WINDOW_RESIZED] = EVENT_HANDLER_WINDOW_RESIZED,
[WINDOW_MINIMIZED] = EVENT_HANDLER_WINDOW_MINIMIZED,
Expand Down
2 changes: 2 additions & 0 deletions src/manifest.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "view.h"
#include "border.h"
#include "window.h"
#include "window_group.h"
#include "application.h"
#include "process_manager.h"
#include "display_manager.h"
Expand All @@ -68,6 +69,7 @@
#include "view.c"
#include "border.c"
#include "window.c"
#include "window_group.c"
#include "application.c"
#include "process_manager.c"
#include "display_manager.c"
Expand Down
Loading

0 comments on commit fa53a84

Please sign in to comment.