Skip to content

Commit

Permalink
WindowServer+LibGUI: Remove old "icon path" way of doing things.
Browse files Browse the repository at this point in the history
Now that we can set icons directly "by bitmap", there's no need for passing
around the icon paths anymore, so get rid of all the IPC and API related
to that. :^)
  • Loading branch information
awesomekling committed Jul 28, 2019
1 parent 841b2e5 commit d4892b3
Show file tree
Hide file tree
Showing 13 changed files with 3 additions and 158 deletions.
16 changes: 1 addition & 15 deletions Applications/Taskbar/TaskbarWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,11 @@ void TaskbarWindow::wm_event(GWMEvent& event)
#endif
break;
}
case GEvent::WM_WindowIconChanged: {
auto& changed_event = static_cast<GWMWindowIconChangedEvent&>(event);
#ifdef EVENT_DEBUG
dbgprintf("WM_WindowIconChanged: client_id=%d, window_id=%d, icon_path=%s\n",
changed_event.client_id(),
changed_event.window_id(),
changed_event.icon_path().characters());
#endif
if (auto* window = WindowList::the().window(identifier)) {
window->set_icon_path(changed_event.icon_path());
window->button()->set_icon(window->icon());
}
break;
}

case GEvent::WM_WindowIconBitmapChanged: {
auto& changed_event = static_cast<GWMWindowIconBitmapChangedEvent&>(event);
#ifdef EVENT_DEBUG
dbgprintf("WM_WindowIconChanged: client_id=%d, window_id=%d, icon_buffer_id=%d\n",
dbgprintf("WM_WindowIconBitmapChanged: client_id=%d, window_id=%d, icon_buffer_id=%d\n",
changed_event.client_id(),
changed_event.window_id(),
changed_event.icon_buffer_id());
Expand Down
13 changes: 0 additions & 13 deletions Applications/Taskbar/WindowList.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,13 @@ class Window {
void set_minimized(bool minimized) { m_minimized = minimized; }
bool is_minimized() const { return m_minimized; }

String icon_path() const { return m_icon_path; }
void set_icon_path(const String& icon_path)
{
if (m_icon_path == icon_path)
return;
auto icon = GraphicsBitmap::load_from_file(icon_path);
if (!icon)
return;
m_icon_path = icon_path;
m_icon = move(icon);
}

const GraphicsBitmap* icon() const { return m_icon.ptr(); }

private:
WindowIdentifier m_identifier;
String m_title;
Rect m_rect;
GButton* m_button { nullptr };
String m_icon_path;
RefPtr<GraphicsBitmap> m_icon;
bool m_active { false };
bool m_minimized { false };
Expand Down
15 changes: 0 additions & 15 deletions Libraries/LibGUI/GEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class GEvent : public CEvent {
WM_WindowRemoved,
WM_WindowStateChanged,
WM_WindowRectChanged,
WM_WindowIconChanged,
WM_WindowIconBitmapChanged,
__End_WM_Events,
};
Expand Down Expand Up @@ -120,20 +119,6 @@ class GWMWindowRectChangedEvent : public GWMEvent {
Rect m_rect;
};

class GWMWindowIconChangedEvent : public GWMEvent {
public:
GWMWindowIconChangedEvent(int client_id, int window_id, const StringView& icon_path)
: GWMEvent(GEvent::Type::WM_WindowIconChanged, client_id, window_id)
, m_icon_path(icon_path)
{
}

String icon_path() const { return m_icon_path; }

private:
String m_icon_path;
};

class GWMWindowIconBitmapChangedEvent : public GWMEvent {
public:
GWMWindowIconBitmapChangedEvent(int client_id, int window_id, int icon_buffer_id, const Size& icon_size)
Expand Down
2 changes: 0 additions & 2 deletions Libraries/LibGUI/GEventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ void GWindowServerConnection::handle_wm_event(const WSAPI_ServerMessage& event,
CEventLoop::current().post_event(window, make<GWMWindowStateChangedEvent>(event.wm.client_id, event.wm.window_id, String(event.text, event.text_length), event.wm.rect, event.wm.is_active, (GWindowType)event.wm.window_type, event.wm.is_minimized));
else if (event.type == WSAPI_ServerMessage::WM_WindowRectChanged)
CEventLoop::current().post_event(window, make<GWMWindowRectChangedEvent>(event.wm.client_id, event.wm.window_id, event.wm.rect));
else if (event.type == WSAPI_ServerMessage::WM_WindowIconChanged)
CEventLoop::current().post_event(window, make<GWMWindowIconChangedEvent>(event.wm.client_id, event.wm.window_id, String(event.text, event.text_length)));
else if (event.type == WSAPI_ServerMessage::WM_WindowIconBitmapChanged)
CEventLoop::current().post_event(window, make<GWMWindowIconBitmapChangedEvent>(event.wm.client_id, event.wm.window_id, event.wm.icon_buffer_id, event.wm.icon_size));
else if (event.type == WSAPI_ServerMessage::WM_WindowRemoved)
Expand Down
16 changes: 0 additions & 16 deletions Libraries/LibGUI/GWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,22 +643,6 @@ void GWindow::set_icon(const GraphicsBitmap* icon)
GWindowServerConnection::the().post_message_to_server(message);
}

void GWindow::set_icon_path(const StringView& path)
{
if (m_icon_path == path)
return;
m_icon_path = path;
if (!m_window_id)
return;
WSAPI_ClientMessage message;
message.type = WSAPI_ClientMessage::Type::SetWindowIcon;
message.window_id = m_window_id;
ASSERT(path.length() < (int)sizeof(message.text));
strcpy(message.text, String(path).characters());
message.text_length = path.length();
GWindowServerConnection::the().post_message_to_server(message);
}

void GWindow::start_wm_resize()
{
WSAPI_ClientMessage message;
Expand Down
4 changes: 0 additions & 4 deletions Libraries/LibGUI/GWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ class GWindow : public CObject {

void set_override_cursor(GStandardCursor);

String icon_path() const { return m_icon_path; }
void set_icon_path(const StringView&);

void set_icon(const GraphicsBitmap*);
const GraphicsBitmap* icon() const { return m_icon.ptr(); }

Expand Down Expand Up @@ -154,7 +151,6 @@ class GWindow : public CObject {
WeakPtr<GWidget> m_hovered_widget;
Rect m_rect_when_windowless;
String m_title_when_windowless;
String m_icon_path;
Vector<Rect, 32> m_pending_paint_event_rects;
Size m_size_increment;
Size m_base_size;
Expand Down
2 changes: 0 additions & 2 deletions Servers/WindowServer/WSAPITypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ struct WSAPI_ServerMessage {
WM_WindowRemoved,
WM_WindowStateChanged,
WM_WindowRectChanged,
WM_WindowIconChanged,
WM_WindowIconBitmapChanged,
__End_WM_Events__,
};
Expand Down Expand Up @@ -232,7 +231,6 @@ struct WSAPI_ClientMessage {
WM_PopupWindowMenu,
PopupMenu,
DismissMenu,
SetWindowIcon,
SetWindowHasAlphaChannel,
MoveWindowToFront,
SetWindowIconBitmap,
Expand Down
31 changes: 0 additions & 31 deletions Servers/WindowServer/WSClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ bool WSClientConnection::handle_message(const WSAPI_ClientMessage& message, cons
case WSAPI_ClientMessage::Type::DismissMenu:
CEventLoop::current().post_event(*this, make<WSAPIDismissMenuRequest>(client_id(), message.menu.menu_id));
break;
case WSAPI_ClientMessage::Type::SetWindowIcon:
if (message.text_length > (int)sizeof(message.text)) {
did_misbehave();
return false;
}
CEventLoop::current().post_event(*this, make<WSAPISetWindowIconRequest>(client_id(), message.window_id, String(message.text, message.text_length)));
break;
case WSAPI_ClientMessage::Type::SetWindowIconBitmap:
CEventLoop::current().post_event(*this, make<WSAPISetWindowIconBitmapRequest>(client_id(), message.window_id, message.window.icon_buffer_id, message.window.icon_size));
break;
Expand Down Expand Up @@ -577,28 +570,6 @@ void WSClientConnection::handle_request(const WSAPIGetWindowTitleRequest& reques
post_message(response);
}

void WSClientConnection::handle_request(const WSAPISetWindowIconRequest& request)
{
int window_id = request.window_id();
auto it = m_windows.find(window_id);
if (it == m_windows.end()) {
post_error("WSAPISetWindowIconRequest: Bad window ID");
return;
}
auto& window = *(*it).value;
if (request.icon_path().is_empty()) {
window.set_default_icon();
} else {
auto icon = GraphicsBitmap::load_from_file(request.icon_path());
if (!icon)
return;
window.set_icon(request.icon_path(), *icon);
}

window.frame().invalidate_title_bar();
WSWindowManager::the().tell_wm_listeners_window_icon_changed(window);
}

void WSClientConnection::handle_request(const WSAPISetWindowIconBitmapRequest& request)
{
int window_id = request.window_id();
Expand Down Expand Up @@ -970,8 +941,6 @@ void WSClientConnection::on_request(const WSAPIClientRequest& request)
return handle_request(static_cast<const WSAPISetWindowRectRequest&>(request));
case WSEvent::APIGetWindowRectRequest:
return handle_request(static_cast<const WSAPIGetWindowRectRequest&>(request));
case WSEvent::APISetWindowIconRequest:
return handle_request(static_cast<const WSAPISetWindowIconRequest&>(request));
case WSEvent::APISetWindowIconBitmapRequest:
return handle_request(static_cast<const WSAPISetWindowIconBitmapRequest&>(request));
case WSEvent::APISetClipboardContentsRequest:
Expand Down
1 change: 0 additions & 1 deletion Servers/WindowServer/WSClientConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class WSClientConnection final : public IPC::Server::Connection<WSAPI_ServerMess
void handle_request(const WSAPIGetWindowTitleRequest&);
void handle_request(const WSAPISetWindowRectRequest&);
void handle_request(const WSAPIGetWindowRectRequest&);
void handle_request(const WSAPISetWindowIconRequest&);
void handle_request(const WSAPISetWindowIconBitmapRequest&);
void handle_request(const WSAPISetClipboardContentsRequest&);
void handle_request(const WSAPIGetClipboardContentsRequest&);
Expand Down
33 changes: 0 additions & 33 deletions Servers/WindowServer/WSEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class WSEvent : public CEvent {
WM_WindowRemoved,
WM_WindowStateChanged,
WM_WindowRectChanged,
WM_WindowIconChanged,
WM_WindowIconBitmapChanged,

__Begin_API_Client_Requests,
Expand All @@ -50,7 +49,6 @@ class WSEvent : public CEvent {
APIGetWindowTitleRequest,
APISetWindowRectRequest,
APIGetWindowRectRequest,
APISetWindowIconRequest,
APISetWindowIconBitmapRequest,
APIInvalidateRectRequest,
APIDidFinishPaintingNotification,
Expand Down Expand Up @@ -573,23 +571,6 @@ class WSAPISetWindowRectRequest final : public WSAPIClientRequest {
Rect m_rect;
};

class WSAPISetWindowIconRequest final : public WSAPIClientRequest {
public:
explicit WSAPISetWindowIconRequest(int client_id, int window_id, const String& icon_path)
: WSAPIClientRequest(WSEvent::APISetWindowIconRequest, client_id)
, m_window_id(window_id)
, m_icon_path(icon_path)
{
}

int window_id() const { return m_window_id; }
String icon_path() const { return m_icon_path; }

private:
int m_window_id { 0 };
String m_icon_path;
};

class WSAPISetWindowIconBitmapRequest final : public WSAPIClientRequest {
public:
explicit WSAPISetWindowIconBitmapRequest(int client_id, int window_id, int icon_buffer_id, const Size& icon_size)
Expand Down Expand Up @@ -864,20 +845,6 @@ class WSWMWindowStateChangedEvent : public WSWMEvent {
bool m_minimized;
};

class WSWMWindowIconChangedEvent : public WSWMEvent {
public:
WSWMWindowIconChangedEvent(int client_id, int window_id, const String& icon_path)
: WSWMEvent(WSEvent::WM_WindowIconChanged, client_id, window_id)
, m_icon_path(icon_path)
{
}

String icon_path() const { return m_icon_path; }

private:
String m_icon_path;
};

class WSWMWindowIconBitmapChangedEvent : public WSWMEvent {
public:
WSWMWindowIconBitmapChangedEvent(int client_id, int window_id, int icon_buffer_id, const Size& icon_size)
Expand Down
14 changes: 0 additions & 14 deletions Servers/WindowServer/WSWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ WSWindow::WSWindow(CObject& internal_owner, WSWindowType type)
: m_internal_owner(&internal_owner)
, m_type(type)
, m_icon(default_window_icon())
, m_icon_path(default_window_icon_path())
, m_frame(*this)
{
WSWindowManager::the().add_window(*this);
Expand All @@ -36,7 +35,6 @@ WSWindow::WSWindow(WSClientConnection& client, WSWindowType window_type, int win
, m_fullscreen(fullscreen)
, m_window_id(window_id)
, m_icon(default_window_icon())
, m_icon_path(default_window_icon_path())
, m_frame(*this)
{
// FIXME: This should not be hard-coded here.
Expand Down Expand Up @@ -243,17 +241,6 @@ void WSWindow::event(CEvent& event)
break;
}

case WSEvent::WM_WindowIconChanged: {
auto& changed_event = static_cast<const WSWMWindowIconChangedEvent&>(event);
server_message.type = WSAPI_ServerMessage::Type::WM_WindowIconChanged;
server_message.wm.client_id = changed_event.client_id();
server_message.wm.window_id = changed_event.window_id();
ASSERT(changed_event.icon_path().length() < (int)sizeof(server_message.text));
memcpy(server_message.text, changed_event.icon_path().characters(), changed_event.icon_path().length());
server_message.text_length = changed_event.icon_path().length();
break;
}

case WSEvent::WM_WindowIconBitmapChanged: {
auto& changed_event = static_cast<const WSWMWindowIconBitmapChangedEvent&>(event);
server_message.type = WSAPI_ServerMessage::Type::WM_WindowIconBitmapChanged;
Expand Down Expand Up @@ -321,7 +308,6 @@ bool WSWindow::is_blocked_by_modal_window() const
void WSWindow::set_default_icon()
{
m_icon = default_window_icon();
m_icon_path = default_window_icon_path();
}

void WSWindow::request_update(const Rect& rect)
Expand Down
7 changes: 0 additions & 7 deletions Servers/WindowServer/WSWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ class WSWindow final : public CObject
const GraphicsBitmap& icon() const { return *m_icon; }
void set_icon(NonnullRefPtr<GraphicsBitmap>&& icon) { m_icon = move(icon); }

String icon_path() const { return m_icon_path; }
void set_icon(const String& path, NonnullRefPtr<GraphicsBitmap>&& icon)
{
m_icon_path = path;
m_icon = move(icon);
}
void set_default_icon();

const WSCursor* override_cursor() const { return m_override_cursor.ptr(); }
Expand Down Expand Up @@ -176,7 +170,6 @@ class WSWindow final : public CObject
Size m_size_increment;
Size m_base_size;
NonnullRefPtr<GraphicsBitmap> m_icon;
String m_icon_path;
RefPtr<WSCursor> m_override_cursor;
WSWindowFrame m_frame;
Color m_background_color { Color::WarmGray };
Expand Down
7 changes: 2 additions & 5 deletions Servers/WindowServer/WSWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,8 @@ void WSWindowManager::tell_wm_listener_about_window_icon(WSWindow& listener, WSW
{
if (!(listener.wm_event_mask() & WSAPI_WMEventMask::WindowIconChanges))
return;
if (window.client()) {
CEventLoop::current().post_event(listener, make<WSWMWindowIconChangedEvent>(window.client()->client_id(), window.window_id(), window.icon_path()));
if (window.icon().shared_buffer_id() != -1)
CEventLoop::current().post_event(listener, make<WSWMWindowIconBitmapChangedEvent>(window.client()->client_id(), window.window_id(), window.icon().shared_buffer_id(), window.icon().size()));
}
if (window.client() && window.icon().shared_buffer_id() != -1)
CEventLoop::current().post_event(listener, make<WSWMWindowIconBitmapChangedEvent>(window.client()->client_id(), window.window_id(), window.icon().shared_buffer_id(), window.icon().size()));
}

void WSWindowManager::tell_wm_listeners_window_state_changed(WSWindow& window)
Expand Down

0 comments on commit d4892b3

Please sign in to comment.