Skip to content

Commit

Permalink
koekeishiya#109 try to workaround weird resizing issues that occur fo…
Browse files Browse the repository at this point in the history
…r some applications
  • Loading branch information
koekeishiya committed Dec 6, 2020
1 parent 88bc42e commit 3fe4c77
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 33 deletions.
2 changes: 0 additions & 2 deletions src/application.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ struct application *application_create(struct process *process)
struct application *application = malloc(sizeof(struct application));
memset(application, 0, sizeof(struct application));
application->ref = AXUIElementCreateApplication(process->pid);
AXUIElementSetAttributeValue(application->ref, kAXEnhancedUserInterface, kCFBooleanFalse);
AXUIElementSetAttributeValue(application->ref, kAXManualAccessibility, kCFBooleanTrue);
application->psn = process->psn;
application->pid = process->pid;
application->name = process->name;
Expand Down
3 changes: 0 additions & 3 deletions src/application.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef APPLICATION_H
#define APPLICATION_H

const CFStringRef kAXEnhancedUserInterface = CFSTR("AXEnhancedUserInterface");
const CFStringRef kAXManualAccessibility = CFSTR("AXManualAccessibility");

#define OBSERVER_CALLBACK(name) void name(AXObserverRef observer, AXUIElementRef element, CFStringRef notification, void *context)
typedef OBSERVER_CALLBACK(observer_callback);

Expand Down
11 changes: 1 addition & 10 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,16 +747,7 @@ static EVENT_CALLBACK(EVENT_HANDLER_MOUSE_DRAGGED)
if (point.x > frame_mid.x) direction |= HANDLE_RIGHT;
if (point.y > frame_mid.y) direction |= HANDLE_BOTTOM;

int x_mod = (direction & HANDLE_LEFT) ? -1 : (direction & HANDLE_RIGHT) ? 1 : 0;
int y_mod = (direction & HANDLE_TOP) ? -1 : (direction & HANDLE_BOTTOM) ? 1 : 0;

float fw = max(1, frame.size.width + dx * x_mod);
float fh = max(1, frame.size.height + dy * y_mod);
float fx = (direction & HANDLE_LEFT) ? frame.origin.x + frame.size.width - fw : frame.origin.x;
float fy = (direction & HANDLE_TOP) ? frame.origin.y + frame.size.height - fh : frame.origin.y;

if (fx != 0.0f || fy != 0.0f) window_manager_move_window(g_mouse_state.window, fx, fy);
if (fw != 0.0f || fh != 0.0f) window_manager_resize_window(g_mouse_state.window, fw, fh);
_window_manager_resize_window_relative(g_mouse_state.window, frame, direction, dx, dy);

g_mouse_state.last_moved_time = event_time;
g_mouse_state.down_location = point;
Expand Down
32 changes: 32 additions & 0 deletions src/misc/helpers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef HELPERS_H
#define HELPERS_H

const CFStringRef kAXEnhancedUserInterface = CFSTR("AXEnhancedUserInterface");

static const char *bool_str[] = { "off", "on" };

static const char *layer_str[] =
Expand Down Expand Up @@ -264,6 +266,36 @@ static inline pid_t ax_window_pid(AXUIElementRef ref)
return *(pid_t *)((void *) ref + 0x10);
}

static inline bool ax_enhanced_userinterface(AXUIElementRef ref)
{
Boolean result = 0;
CFTypeRef value;

if (AXUIElementCopyAttributeValue(ref, kAXEnhancedUserInterface, &value) == kAXErrorSuccess) {
result = CFBooleanGetValue(value);
CFRelease(value);
}

return result;
}

static inline void set_ax_enhanced_userinterface(AXUIElementRef ref, bool value)
{
if (value) {
AXUIElementSetAttributeValue(ref, kAXEnhancedUserInterface, kCFBooleanTrue);
} else {
AXUIElementSetAttributeValue(ref, kAXEnhancedUserInterface, kCFBooleanFalse);
}
}

#define AX_ENHANCED_UI_WORKAROUND(r, c) \
{\
bool eui = ax_enhanced_userinterface(r); \
if (eui) set_ax_enhanced_userinterface(r, false); \
c \
if (eui) set_ax_enhanced_userinterface(r, true); \
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
static inline bool psn_equals(ProcessSerialNumber *a, ProcessSerialNumber *b)
Expand Down
50 changes: 32 additions & 18 deletions src/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,29 @@ enum window_op_error window_manager_move_window_relative(struct window_manager *
dy += frame.origin.y;
}

window_manager_move_window(window, dx, dy);
AX_ENHANCED_UI_WORKAROUND(window->application->ref, {
window_manager_move_window(window, dx, dy);
});

return WINDOW_OP_ERROR_SUCCESS;
}

void _window_manager_resize_window_relative(struct window *window, CGRect frame, int direction, float dx, float dy)
{
int x_mod = (direction & HANDLE_LEFT) ? -1 : (direction & HANDLE_RIGHT) ? 1 : 0;
int y_mod = (direction & HANDLE_TOP) ? -1 : (direction & HANDLE_BOTTOM) ? 1 : 0;

float fw = max(1, frame.size.width + dx * x_mod);
float fh = max(1, frame.size.height + dy * y_mod);
float fx = (direction & HANDLE_LEFT) ? frame.origin.x + frame.size.width - fw : frame.origin.x;
float fy = (direction & HANDLE_TOP) ? frame.origin.y + frame.size.height - fh : frame.origin.y;

AX_ENHANCED_UI_WORKAROUND(window->application->ref, {
window_manager_move_window(window, fx, fy);
window_manager_resize_window(window, fw, fh);
});
}

enum window_op_error window_manager_resize_window_relative(struct window_manager *wm, struct window *window, int direction, float dx, float dy)
{
struct view *view = window_manager_find_managed_window(wm, window);
Expand Down Expand Up @@ -385,19 +403,11 @@ enum window_op_error window_manager_resize_window_relative(struct window_manager
view_flush(view);
} else {
if (direction == HANDLE_ABS) {
window_manager_resize_window(window, dx, dy);
AX_ENHANCED_UI_WORKAROUND(window->application->ref, {
window_manager_resize_window(window, dx, dy);
});
} else {
int x_mod = (direction & HANDLE_LEFT) ? -1 : (direction & HANDLE_RIGHT) ? 1 : 0;
int y_mod = (direction & HANDLE_TOP) ? -1 : (direction & HANDLE_BOTTOM) ? 1 : 0;

CGRect frame = window_frame(window);
float fw = max(1, frame.size.width + dx * x_mod);
float fh = max(1, frame.size.height + dy * y_mod);
float fx = (direction & HANDLE_LEFT) ? frame.origin.x + frame.size.width - fw : frame.origin.x;
float fy = (direction & HANDLE_TOP) ? frame.origin.y + frame.size.height - fh : frame.origin.y;

window_manager_move_window(window, fx, fy);
window_manager_resize_window(window, fw, fh);
_window_manager_resize_window_relative(window, window_frame(window), direction, dx, dy);
}
}

Expand Down Expand Up @@ -429,9 +439,11 @@ void window_manager_resize_window(struct window *window, float width, float heig

void window_manager_set_window_frame(struct window *window, float x, float y, float width, float height)
{
window_manager_resize_window(window, width, height);
window_manager_move_window(window, x, y);
window_manager_resize_window(window, width, height);
AX_ENHANCED_UI_WORKAROUND(window->application->ref, {
window_manager_resize_window(window, width, height);
window_manager_move_window(window, x, y);
window_manager_resize_window(window, width, height);
});
}

void window_manager_set_purify_mode(struct window_manager *wm, enum purify_mode mode)
Expand Down Expand Up @@ -1303,8 +1315,10 @@ enum window_op_error window_manager_apply_grid(struct space_manager *sm, struct
float fw = cw * w;
float fh = ch * h;

window_manager_move_window(window, fx, fy);
window_manager_resize_window(window, fw, fh);
AX_ENHANCED_UI_WORKAROUND(window->application->ref, {
window_manager_move_window(window, fx, fy);
window_manager_resize_window(window, fw, fh);
});

return WINDOW_OP_ERROR_SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions src/window_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void window_manager_remove_application(struct window_manager *wm, pid_t pid);
void window_manager_add_application(struct window_manager *wm, struct application *application);
struct window **window_manager_find_application_windows(struct window_manager *wm, struct application *application, int *window_count);
enum window_op_error window_manager_move_window_relative(struct window_manager *wm, struct window *window, int type, float dx, float dy);
void _window_manager_resize_window_relative(struct window *window, CGRect frame, int direction, float dx, float dy);
enum window_op_error window_manager_resize_window_relative(struct window_manager *wm, struct window *window, int direction, float dx, float dy);
void window_manager_set_purify_mode(struct window_manager *wm, enum purify_mode mode);
void window_manager_set_active_window_opacity(struct window_manager *wm, float opacity);
Expand Down

0 comments on commit 3fe4c77

Please sign in to comment.