Commit graph

33 commits

Author SHA1 Message Date
Andreas Kling
23e16a3e2e LibGUI: Remove bitrotted automatic keybinds feature
This feature hasn't been working at all for several months, so let's
just remove it and simplify GWindow event handling.
2019-12-27 00:52:30 +01:00
Andreas Kling
43da941de5 LibGUI: Use NeverDestroyed<T> for the global GWindow tables
We don't need these to be destroyed on exit, since that would race with
the destruction of static global RefPtr<GWindow>'s.

Fixes #900.
2019-12-26 22:13:50 +01:00
Andreas Kling
519cb80a96 LibGUI+WindowServer: Mark minimized window backing stores as volatile
WindowServer will now send out a WindowStateChanged message to clients
when one of their windows is minimized.

This is then forwarded to the GWindow, which will try to mark its
underlying window backing store as volatile.

This allows the kernel to steal the memory used by minimized windows
in case it starts running low. Very cool! :^)
2019-12-26 12:06:07 +01:00
Andreas Kling
411058b2a3 WindowServer+LibGUI: Implement basic color theming
Color themes are loaded from .ini files in /res/themes/
The theme can be switched from the "Themes" section in the system menu.

The basic mechanism is that WindowServer broadcasts a SharedBuffer with
all of the color values of the current theme. Clients receive this with
the response to their initial WindowServer::Greet handshake.

When the theme is changed, WindowServer tells everyone by sending out
an UpdateSystemTheme message with a new SharedBuffer to use.

This does feel somewhat bloated somehow, but I'm sure we can iterate on
it over time and improve things.

To get one of the theme colors, use the Color(SystemColor) constructor:

    painter.fill_rect(rect, SystemColor::HoverHighlight);

Some things don't work 100% right without a reboot. Specifically, when
constructing a GWidget, it will set its own background and foreground
colors based on the current SystemColor::Window and SystemColor::Text.
The widget is then stuck with these values, and they don't update on
system theme change, only on app restart.

All in all though, this is pretty cool. Merry Christmas! :^)
2019-12-23 20:33:01 +01:00
Andreas Kling
cfcb38dff1 WindowServer+LibGUI: Add data_type and data fields to drag operations
These fields are intended to carry the real meat of a drag operation,
and the "text" is just for what we show on screen (alongside the cursor
during the actual drag.)

The data field is just a String for now, but in the future we should
make it something more flexible.
2019-12-20 20:07:10 +01:00
Andreas Kling
f8ec8cc255 LibGUI: Mark the first GWindow back bitmap volatile immediately
We were previously waiting until the first bitmap buffer flip happened
before marking the back buffer volatile.
2019-12-09 21:33:39 +01:00
Andreas Kling
dfd0daa157 LibGUI: Mark window back buffers as volatile while not painting
We now take advantage of SharedBuffers being purgeable memory by
setting the volatile flag on window back buffers while not painting
into them.

This means that one of the two backing stores used by each window
is purgeable+volatile most of the time, allowing the kernel to purge
it to recover memory if needed.

Note that this is only relevant when double-buffering is turned on,
but since that is the default, this does affect most apps. :^)
2019-12-09 20:08:44 +01:00
Andreas Kling
6f4c380d95 AK: Use size_t for the length of strings
Using int was a mistake. This patch changes String, StringImpl,
StringView and StringBuilder to use size_t instead of int for lengths.
Obviously a lot of code needs to change as a result of this.
2019-12-09 17:51:21 +01:00
Andreas Kling
a7f414bba7 LibGUI+WindowServer: Start fleshing out drag&drop functionality
This patch enables basic drag&drop between applications.
You initiate a drag by creating a GDragOperation object and calling
exec() on it. This creates a nested event loop in the calling program
that only returns once the drag operation has ended.

On the receiving side, you get a call to GWidget::drop_event() with
a GDropEvent containing information about the dropped data.

The only data passed right now is a piece of text that's also used
to visually indicate that a drag is happening (by showing the text in
a little box that follows the mouse cursor around.)

There are things to fix here, but we're off to a nice start. :^)
2019-12-08 16:50:23 +01:00
Andreas Kling
272d65e3e2 WindowServer: Port to the new IPC system
This patch introduces code generation for the WindowServer IPC with
its clients. The client/server endpoints are defined by the two .ipc
files in Servers/WindowServer/: WindowServer.ipc and WindowClient.ipc

It now becomes significantly easier to add features and capabilities
to WindowServer since you don't have to know nearly as much about all
the intricate paths that IPC messages take between LibGUI and WSWindow.

The new system also uses significantly less IPC bandwidth since we're
now doing packed serialization instead of passing fixed-sized structs
of ~600 bytes for each message.

Some repaint coalescing optimizations are lost in this conversion and
we'll need to look at how to implement those in the new world.

The old CoreIPC::Client::Connection and CoreIPC::Server::Connection
classes are removed by this patch and replaced by use of ConnectionNG,
which will be renamed eventually.

Goodbye, old WindowServer IPC. You served us well :^)
2019-12-02 11:11:05 +01:00
Andreas Kling
8a024a3305 LibGUI: Rename GEventLoop.{cpp,h} => GWindowServerConnection
The GEventLoop class is long gone, and the only class in these files is
GWindowServerConnection, so let's update the file names. :^)
2019-11-08 11:40:25 +01:00
Andreas Kling
98a6149b4f LibGUI: Make GWindow drive relayout and do it recursively
Instead of only doing a relayout in the widget you're invalidating,
we now do a recursive top-down relayout so everything gets updated.

This fixes invalid results after updating a preferred size in some
situations with nested layouts.
2019-10-26 12:28:54 +02:00
Brandon Scott
51e655f903 LibGUI: Added window creation callback to GApplication/GWindow
Added a window creation callback to GApplication that gets called
by GWindow which will reset any pending exit request in the
CEventLoop.

This is to prevent a bug which prevents your application from
starting up if you had a message box or other dialog before
showing your main application form. The bug was triggered by
there being no more visible windows which was triggering a
premature quit().
2019-10-25 15:29:19 +02:00
Andreas Kling
34d0e96aec LibCore+LibGUI: Remove GEventLoop and use CEventLoop everywhere
GEventLoop was just a dummy subclass of CEventLoop anyway. The only
thing it actually did was make sure a GWindowServerConnectionw was
instantiated. We now take care of that in GApplication instead.

CEventLoop is now non-virtual and a little less confusing. :^)
2019-09-22 20:50:39 +02:00
Andreas Kling
870bc2a4d1 LibGUI: Get rid of GWindow's destroy-on-close mechanism
Since we're moving to a world of ref-counting, we can't have weird
behaviors like "windows delete themselves when you close them."

The "close app when there are no more windows" mechanism is moved
to GWindow::hide(). Now, we close the app when it has no more
windows on screen.
2019-09-21 18:53:17 +02:00
Andreas Kling
ff6ce422dd LibGUI: Convert GWidget to ObjectPtr 2019-09-21 17:05:35 +02:00
Andreas Kling
fcc3745b02 LibCore+LibGUI+WindowServer: Make events bubble up through ancestors
With this patch, CEvents no longer stop at the target object, but will
bubble up the ancestor chain as long as CEvent::is_accepted() is false.

To the set accepted flag, call CEvent::accept().
To clear the accepted flag, call CEvent::ignore().

Events start out in the accepted state, so if you want them to bubble
up, you have to call ignore() on them.

Using this mechanism, we now ignore non-tabbing keydown events in
GWidget, causing them to bubble up through the widget's ancestors. :^)
2019-09-20 20:37:31 +02:00
Andreas Kling
d92e26d023 WindowServer+LibGUI: Allow switching windows in/out of fullscreen mode
You can now call GWindow::set_fullscreen(bool) and it will go in or out
of fullscreen mode.

WindowServer will also remember the previous window rect when switching
to fullscreen, and restore it when switching back. :^)
2019-09-16 18:38:42 +02:00
Andreas Kling
c4b1456c88 GWindow: Allow clients to prevent close requests from closing
This is done by hooking the new on_close_request callback and returning
GWindow::CloseRequestDecision::StayOpen (instead of ...::Close.)
2019-08-27 20:35:37 +02:00
Andreas Kling
3792c91059 LibGUI: Implement save_to(JsonObject&) for GWindow and GWidget 2019-08-19 16:34:53 +02:00
Andreas Kling
dc572e31fa LibGUI: Let GWindow::set_main_widget() take ownership of the widget
We were already doing this anyway, with ~GWindow() calling delete on
the main widget.
2019-08-18 12:18:17 +02:00
rhin123
c02868f000 LibGUI: Allow setting window icon before show(). 2019-08-02 21:18:21 +02:00
Andreas Kling
5ded77df39 Kernel+ProcessManager: Let processes have an icon and show it in the table.
Processes can now have an icon assigned, which is essentially a 16x16 RGBA32
bitmap exposed as a shared buffer ID.

You set the icon ID by calling set_process_icon(int) and the icon ID will be
exposed through /proc/all.

To make this work, I added a mechanism for making shared buffers globally
accessible. For safety reasons, each app seals the icon buffer before making
it global.

Right now the first call to GWindow::set_icon() is what determines the
process icon. We'll probably change this in the future. :^)
2019-07-29 07:26:01 +02:00
Andreas Kling
d4892b3fdc WindowServer+LibGUI: Remove old "icon path" way of doing things.
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. :^)
2019-07-28 10:24:58 +02:00
Andreas Kling
841b2e5d13 WindowServer+LibGUI: Pass window icons as shared buffers rather than paths.
Now that we support more than 2 clients per shared buffer, we can use them
for window icons. I didn't do that previously since it would have made the
Taskbar process unable to access the icons.

This opens up some nice possibilities for programmatically generated icons.
2019-07-28 10:18:49 +02:00
Andreas Kling
72a3f69df7 LibGUI: Get rid of GWindow::should_exit_event_loop_on_close().
This behavior and API was extremely counter-intuitive since our default
behavior was for applications to never exit after you close all of their
windows.

Now that we exit the event loop by default when the very last GWindow is
deleted, we don't have to worry about this.
2019-07-23 18:20:00 +02:00
Andreas Kling
fbae03b737 LibGUI: Exit the main event loop when the last window is deleted.
This behavior is the new opt-out default. If you don't want your app to exit
when the last GWindow is destroyed, call this:

    - void GApplication::set_quit_set_quit_when_last_window_deleted(bool)

Also renamed "windows()" to "reified_windows" in GWindow.cpp to reflect that
it only contains GWindows that have a server-side representation. :^)
2019-07-23 18:16:25 +02:00
Andreas Kling
1c0669f010 LibDraw: Introduce (formerly known as SharedGraphics.)
Instead of LibGUI and WindowServer building their own copies of the drawing
and graphics code, let's it in a separate LibDraw library.

This avoids building the code twice, and will encourage better separation
of concerns. :^)
2019-07-18 10:18:16 +02:00
Robin Burchell
b907608e46 SharedBuffer: Split the creation and share steps
This allows us to seal a buffer *before* anyone else has access to it
(well, ok, the creating process still does, but you can't win them all).

It also means that a SharedBuffer can be shared with multiple clients:
all you need is to have access to it to share it on again.
2019-07-18 10:06:20 +02:00
Robin Burchell
7a53096e8d LibGUI: Revert GWindowServerConnection to being a singleton
This was a mistake, of course. Nested event loops don't need (or want)
independent server connections.

We initialize the connection early in GEventLoop for e.g. users that
want to get the size of a GDesktop before the connection has been
established.

Bug noticed by Andreas, introduced by me ;-)
2019-07-17 21:03:01 +02:00
Robin Burchell
2177594c96 Port LibGUI to use CIPCClientSideConnection
As a consequence, move to use an explicit handshake() method rather than
calling virtuals from the constructor. This seemed to not bother
AClientConnection, but LibGUI crashes (rightfully) because of it.
2019-07-17 20:16:44 +02:00
Andreas Kling
0e75aba7c3 StringView: Rename characters() to characters_without_null_termination().
This should make you think twice before trying to use the const char* from
a StringView as if it's a null-terminated string.
2019-07-08 15:38:44 +02:00
Andreas Kling
04b9dc2d30 Libraries: Create top level directory for libraries.
Things were getting a little crowded in the project root, so this patch
moves the Lib*/ directories into Libraries/.
2019-07-04 16:16:50 +02:00
Renamed from LibGUI/GWindow.cpp (Browse further)