Skip to content

Commit

Permalink
WindowServer+LibGUI: Allow changing whether windows have alpha channels.
Browse files Browse the repository at this point in the history
Use this in Terminal to tell the window server to not bother with the alpha
channel in the backing store if we're running without transparency.
Semi-transparent terminals look neat but they slow everything down, so this
keeps things fast while making it easy to switch to the flashy mode. :^)
  • Loading branch information
awesomekling committed May 3, 2019
1 parent 2470fdc commit 6a5d92f
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions Applications/Terminal/Terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ void Terminal::set_opacity(float opacity)
{
if (m_opacity == opacity)
return;
window()->set_has_alpha_channel(opacity < 1);
m_opacity = opacity;
force_repaint();
}
2 changes: 1 addition & 1 deletion Applications/Terminal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int main(int argc, char** argv)
};

slider->set_range(0, 100);
slider->set_value(80);
slider->set_value(100);

auto menubar = make<GMenuBar>();

Expand Down
3 changes: 3 additions & 0 deletions LibGUI/GEventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ bool GEventLoop::wait_for_specific_event(WSAPI_ServerMessage::Type type, WSAPI_S
FD_ZERO(&rfds);
FD_SET(s_event_fd, &rfds);
int rc = select(s_event_fd + 1, &rfds, nullptr, nullptr, nullptr);
if (rc < 0) {
perror("select");
}
ASSERT(rc > 0);
ASSERT(FD_ISSET(s_event_fd, &rfds));
bool success = drain_messages_from_server();
Expand Down
17 changes: 16 additions & 1 deletion LibGUI/GWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,23 @@ void GWindow::set_automatic_cursor_tracking_widget(GWidget* widget)

void GWindow::set_has_alpha_channel(bool value)
{
ASSERT(!m_window_id);
if (m_has_alpha_channel == value)
return;
m_has_alpha_channel = value;
if (!m_window_id)
return;

m_pending_paint_event_rects.clear();
m_back_bitmap = nullptr;
m_front_bitmap = nullptr;

WSAPI_ClientMessage message;
message.type = WSAPI_ClientMessage::Type::SetWindowHasAlphaChannel;
message.window_id = m_window_id;
message.value = value;
GEventLoop::current().sync_request(message, WSAPI_ServerMessage::DidSetWindowHasAlphaChannel);

update();
}

void GWindow::set_double_buffering_enabled(bool value)
Expand Down
2 changes: 2 additions & 0 deletions Servers/WindowServer/WSAPITypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct WSAPI_ServerMessage {
DidSetWindowBackingStore,
DidSetWallpaper,
DidGetWallpaper,
DidSetWindowHasAlphaChannel,
ScreenRectChanged,
WM_WindowRemoved,
WM_WindowStateChanged,
Expand Down Expand Up @@ -218,6 +219,7 @@ struct WSAPI_ClientMessage {
PopupMenu,
DismissMenu,
SetWindowIcon,
SetWindowHasAlphaChannel,
};
Type type { Invalid };
int window_id { -1 };
Expand Down
20 changes: 20 additions & 0 deletions Servers/WindowServer/WSClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,24 @@ void WSClientConnection::handle_request(const WSAPISetWindowOverrideCursorReques
window.set_override_cursor(WSCursor::create(request.cursor()));
}

void WSClientConnection::handle_request(const WSAPISetWindowHasAlphaChannelRequest& request)
{
int window_id = request.window_id();
auto it = m_windows.find(window_id);
if (it == m_windows.end()) {
post_error("WSAPISetWindowHasAlphaChannelRequest: Bad window ID");
return;
}
auto& window = *(*it).value;
window.set_has_alpha_channel(request.value());

WSAPI_ServerMessage response;
response.type = WSAPI_ServerMessage::Type::DidSetWindowHasAlphaChannel;
response.window_id = window_id;
response.value = request.value();
post_message(response);
}

void WSClientConnection::handle_request(const WSWMAPISetActiveWindowRequest& request)
{
auto* client = WSClientConnection::from_client_id(request.target_client_id());
Expand Down Expand Up @@ -747,6 +765,8 @@ void WSClientConnection::on_request(const WSAPIClientRequest& request)
return handle_request(static_cast<const WSAPIPopupMenuRequest&>(request));
case WSEvent::APIDismissMenuRequest:
return handle_request(static_cast<const WSAPIDismissMenuRequest&>(request));
case WSEvent::APISetWindowHasAlphaChannelRequest:
return handle_request(static_cast<const WSAPISetWindowHasAlphaChannelRequest&>(request));
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions Servers/WindowServer/WSClientConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class WSClientConnection final : public CObject {
void handle_request(const WSWMAPIStartWindowResizeRequest&);
void handle_request(const WSAPIPopupMenuRequest&);
void handle_request(const WSAPIDismissMenuRequest&);
void handle_request(const WSAPISetWindowHasAlphaChannelRequest&);

void post_error(const String&);

Expand Down
18 changes: 18 additions & 0 deletions Servers/WindowServer/WSEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class WSEvent : public CEvent {
APISetWallpaperRequest,
APIGetWallpaperRequest,
APISetWindowOverrideCursorRequest,
APISetWindowHasAlphaChannelRequest,
WMAPISetActiveWindowRequest,
WMAPISetWindowMinimizedRequest,
WMAPIStartWindowResizeRequest,
Expand Down Expand Up @@ -387,6 +388,23 @@ class WSAPISetWindowOverrideCursorRequest final : public WSAPIClientRequest {
WSStandardCursor m_cursor { WSStandardCursor::None };
};

class WSAPISetWindowHasAlphaChannelRequest final : public WSAPIClientRequest {
public:
explicit WSAPISetWindowHasAlphaChannelRequest(int client_id, int window_id, bool value)
: WSAPIClientRequest(WSEvent::APISetWindowHasAlphaChannelRequest, client_id)
, m_window_id(window_id)
, m_value(value)
{
}

int window_id() const { return m_window_id; }
bool value() const { return m_value; }

private:
int m_window_id { 0 };
bool m_value { 0 };
};

class WSAPISetWallpaperRequest final : public WSAPIClientRequest {
public:
explicit WSAPISetWallpaperRequest(int client_id, String&& wallpaper)
Expand Down
3 changes: 3 additions & 0 deletions Servers/WindowServer/WSEventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ bool WSEventLoop::on_receive_from_client(int client_id, const WSAPI_ClientMessag
case WSAPI_ClientMessage::Type::SetWindowOverrideCursor:
post_event(client, make<WSAPISetWindowOverrideCursorRequest>(client_id, message.window_id, (WSStandardCursor)message.cursor.cursor));
break;
case WSAPI_ClientMessage::SetWindowHasAlphaChannel:
post_event(client, make<WSAPISetWindowHasAlphaChannelRequest>(client_id, message.window_id, message.value));
break;
case WSAPI_ClientMessage::Type::WM_SetActiveWindow:
post_event(client, make<WSWMAPISetActiveWindowRequest>(client_id, message.wm.client_id, message.wm.window_id));
break;
Expand Down

0 comments on commit 6a5d92f

Please sign in to comment.