Skip to content

Commit

Permalink
koekeishiya#637 fix dubious autofocus stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya authored and unrevre committed Aug 11, 2020
1 parent 38fcf89 commit 4b5f7b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Update scripting-addition to support macOS Big Sur 10.16 Build 20A5343i [#589](https://github.com/koekeishiya/yabai/issues/589)
- Border windows should not have shadows [#617](https://github.com/koekeishiya/yabai/issues/617)
- *external_bar* should not have to be set before regular padding [#615](https://github.com/koekeishiya/yabai/issues/615)
- Adjust reported mouse location to use when synthesizing events for ffm autofocus [#637](https://github.com/koekeishiya/yabai/issues/637)

## [3.2.1] - 2020-06-17
### Changed
- Fixed a race condition upon receiving window destroy notifications from macOS because their API is garbage and reports duplicate notifications for the same window [#580](https://github.com/koekeishiya/yabai/issues/580)
- focus-follows-mouse *autofocus* needs to perform some validation in order to see if the window is focusable [#578](https://github.com/koekeishiya/yabai/issues/578)
- Properly set mouse location for synthesized events used by ffm autofocus [#545](https://github.com/koekeishiya/yabai/issues/545)

## [3.2.0] - 2020-06-14
### Added
Expand Down
51 changes: 8 additions & 43 deletions src/window_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,23 +764,8 @@ struct window *window_manager_find_smallest_managed_window(struct space_manager

static void window_manager_make_key_window(ProcessSerialNumber *window_psn, uint32_t window_id)
{
uint8_t bytes1[0xf8] = {
[0x04] = 0xf8,
[0x08] = 0x01,
[0x26] = 0xf0,
[0x27] = 0xbf,
[0x2e] = 0xf0,
[0x2f] = 0xbf
};

uint8_t bytes2[0xf8] = {
[0x04] = 0xf8,
[0x08] = 0x02,
[0x26] = 0xf0,
[0x27] = 0xbf,
[0x2e] = 0xf0,
[0x2f] = 0xbf
};
uint8_t bytes1[0xf8] = { [0x04] = 0xf8, [0x08] = 0x01, [0x26] = 0xef, [0x27] = 0x7f, [0x2e] = 0xef, [0x2f] = 0x7f };
uint8_t bytes2[0xf8] = { [0x04] = 0xf8, [0x08] = 0x02, [0x26] = 0xef, [0x27] = 0x7f, [0x2e] = 0xef, [0x2f] = 0x7f };

memcpy(bytes1 + 0x3c, &window_id, sizeof(uint32_t));
memcpy(bytes2 + 0x3c, &window_id, sizeof(uint32_t));
Expand All @@ -789,42 +774,22 @@ static void window_manager_make_key_window(ProcessSerialNumber *window_psn, uint
SLPSPostEventRecordTo(window_psn, bytes2);
}

static void window_manager_deactivate_window(ProcessSerialNumber *window_psn, uint32_t window_id)
{
uint8_t bytes[0xf8] = {
[0x04] = 0xf8,
[0x08] = 0x0d,
[0x8a] = 0x02
};

memcpy(bytes + 0x3c, &window_id, sizeof(uint32_t));
SLPSPostEventRecordTo(window_psn, bytes);
}

static void window_manager_activate_window(ProcessSerialNumber *window_psn, uint32_t window_id)
{
uint8_t bytes[0xf8] = {
[0x04] = 0xf8,
[0x08] = 0x0d,
[0x8a] = 0x01
};

memcpy(bytes + 0x3c, &window_id, sizeof(uint32_t));
SLPSPostEventRecordTo(window_psn, bytes);
}

void window_manager_focus_window_without_raise(ProcessSerialNumber *window_psn, uint32_t window_id)
{
if (psn_equals(window_psn, &g_window_manager.focused_window_psn)) {
window_manager_deactivate_window(&g_window_manager.focused_window_psn, g_window_manager.focused_window_id);
uint8_t bytes1[0xf8] = { [0x04] = 0xf8, [0x08] = 0x0d, [0x8a] = 0x02 };
memcpy(bytes1 + 0x3c, &g_window_manager.focused_window_id, sizeof(uint32_t));
SLPSPostEventRecordTo(&g_window_manager.focused_window_psn, bytes1);

// @hack
// Artificially delay the activation by 1ms. This is necessary
// because some applications appear to be confused if both of
// the events appear instantaneously.
usleep(10000);

window_manager_activate_window(window_psn, window_id);
uint8_t bytes2[0xf8] = { [0x04] = 0xf8, [0x08] = 0x0d, [0x8a] = 0x01 };
memcpy(bytes2 + 0x3c, &window_id, sizeof(uint32_t));
SLPSPostEventRecordTo(window_psn, bytes2);
}

_SLPSSetFrontProcessWithOptions(window_psn, window_id, kCPSUserGenerated);
Expand Down

0 comments on commit 4b5f7b6

Please sign in to comment.