Skip to content

Commit

Permalink
fix wrong focused client when switching to a workspace with a fullscr…
Browse files Browse the repository at this point in the history
…een client
  • Loading branch information
aesophor committed Feb 27, 2020
1 parent f312bc5 commit 4ded7f4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
20 changes: 15 additions & 5 deletions src/window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,17 @@ void WindowManager::ArrangeWindows() const {

if (workspaces_[current_]->is_fullscreen()) {
UnmapDocks();
// At this point, we have to consider two cases:
// 1. `focused_client` is not mapped yet.
// 2. `focused_client` is already mapped.
//
// If we simply call UnmapAllClients() and focused_client->Map(),
// then the fullscreen window will "blink", which is not desirable.
//
// Therefore, we'll UnmapAllClients() except the focused_client
// but still call focused_client->Map() just in case it's not mapped yet.
workspaces_[current_]->UnmapAllClients(/*except_window=*/focused_client->window());
focused_client->Map();
focused_client->SetBorderWidth(0);
focused_client->MoveResize(0, 0, GetDisplayResolution());
focused_client->workspace()->SetFocusedClient(focused_client->window());
Expand Down Expand Up @@ -419,7 +430,7 @@ void WindowManager::OnButtonRelease(const XButtonEvent&) {
GET_CLIENT_OR_RETURN(btn_pressed_event_.subwindow, c);

c->workspace()->EnableFocusFollowsMouse();

if (c->is_floating()) {
XWindowAttributes attr = wm_utils::GetXWindowAttributes(btn_pressed_event_.subwindow);
cookie_.Put(c->window(), {attr.x, attr.y, attr.width, attr.height});
Expand Down Expand Up @@ -635,7 +646,6 @@ void WindowManager::GotoWorkspace(int next) {
}

workspaces_[current_]->UnmapAllClients();
workspaces_[next]->MapAllClients();
current_ = next;
ArrangeWindows();

Expand All @@ -649,7 +659,7 @@ void WindowManager::MoveWindowToWorkspace(Window window, int next) {
GET_CLIENT_OR_RETURN(window, c);

// Return early if current_ == next or `next` is out of bounds.
if (current_ == next || next < 0 || next >= (int) workspaces_.size()) {
if (current_ == next || next < 0 || next >= (int)workspaces_.size()) {
return;
}

Expand Down Expand Up @@ -692,11 +702,11 @@ void WindowManager::SetFullscreen(Window window, bool fullscreen) {
c->workspace()->set_fullscreen(fullscreen);

if (fullscreen) {
// Save the window's position and size before resizing it to fullscreen.
c->set_attr_cache(c->GetXWindowAttributes());
c->workspace()->UnmapAllClients();
c->Map();
c->SetBorderWidth(0); // Weird workaround for "doubled visioned" KDE logout screen :(
} else {
// Restore the window's position and size.
const XWindowAttributes& attr = c->attr_cache();
c->SetBorderWidth(config_->border_width());
c->MoveResize(attr.x, attr.y, attr.width, attr.height);
Expand Down
7 changes: 4 additions & 3 deletions src/workspace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ void Workspace::MapAllClients() const {
}
}

void Workspace::UnmapAllClients() const {
void Workspace::UnmapAllClients(Window except_window) const {
for (const auto c : GetClients()) {
c->Unmap();
if (c->window() != except_window) {
c->Unmap();
}
}
}

Expand Down Expand Up @@ -361,7 +363,6 @@ vector<Client*> Workspace::GetTilingClients() const {
return clients;
}


Config* Workspace::config() const {
return config_;
}
Expand Down
2 changes: 1 addition & 1 deletion src/workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Workspace {
void SetTilingDirection(TilingDirection tiling_direction);

void MapAllClients() const;
void UnmapAllClients() const;
void UnmapAllClients(Window except_window = None) const;
void RaiseAllFloatingClients() const;
void SetFocusedClient(Window window);
void UnsetFocusedClient() const;
Expand Down

0 comments on commit 4ded7f4

Please sign in to comment.