Commit Graph

451 Commits

Author SHA1 Message Date
Andreas Kling
58823c474e WindowServer: Don't let super key open system menu while tracking input
Previously it was possible to open the system menu while tracking mouse
input after a mousedown event.
2021-06-18 17:40:05 +02:00
Andreas Kling
82a945fa7e WindowServer: Always send mouse events to active input tracker first
If a window is currently actively tracking input events (because
sent it a MouseDown and haven't sent it a MouseUp yet), we now simply
send mouse events to that window right away before doing any other
event processing.

This makes it much easier to reason about mouse events.
2021-06-18 17:40:05 +02:00
Andreas Kling
69dad3b996 WindowServer: Remove an unnecessary temporary variable 2021-06-18 17:40:05 +02:00
Andreas Kling
ad828b3cfc WindowServer: Split up WindowFrame::handle_mouse_event()
Break this function into a couple of smaller functions, one for each
of these areas:

- The titlebar
- The titlebar icon
- The menubar
- The border
2021-06-18 17:40:05 +02:00
Andreas Kling
f88361fc28 WindowServer: Add WindowStack::window_at() and use it a bunch
This performs a hit test on the window stack to find the window under
a given cursor position.
2021-06-18 17:40:05 +02:00
Andreas Kling
4133caba78 WindowServer: Make hit test results richer
Instead of just answering hit/no-hit when hit testing windows, we now
return a HitTestResult object which tells you which window was hit,
where it was hit, and whether you hit the frame or the content.
2021-06-18 17:40:05 +02:00
Andreas Kling
370d3749e5 WindowServer: Remove weird feature where Ctrl+Wheel changed opacity
This feature had been there since early on and was not actually useful
for anything. I just added it because it was fun. In retrospect, it's
not a very good feature and I only ever activated it by accident.
2021-06-18 17:40:05 +02:00
Andreas Kling
e4e94cd43d WindowServer: Allow each WindowStack to have an active window
A window with an inner stack needs to keep track of which inner window
is active.
2021-06-18 17:40:05 +02:00
Andreas Kling
2b0e0b602c WindowServer: Keep track of which WindowStack a Window is part of
Each Window now knows which WindowStack it's part of. We call this the
Window::outer_stack(), in preparation for supporting inner stacks. :^)
2021-06-18 17:40:05 +02:00
Andreas Kling
d0bc3d6002 WindowServer: Convert WindowManager to east-const style 2021-06-18 17:40:05 +02:00
Andreas Kling
d257f58306 WindowServer: Add WindowStack concept
This patch moves the window stack out of WindowManager and into its own
WindowStack class.

A WindowStack is an ordered list of windows with an optional highlight
window. The highlight window mechanism is used during Super+Tab window
switching to temporarily bring a window to the front.

This is mostly mechanical, just moving the code to its own class.
2021-06-18 17:40:05 +02:00
Gunnar Beutner
631d36fd98 Everywhere: Add component declarations
This adds component declarations so that users can select to not build
certain parts of the OS.
2021-06-17 11:03:51 +02:00
Andreas Kling
88b168ff16 WindowServer: Simplify WindowFrame shadow logic a little bit
Remove the confusingly-named inflate_for_shadow() function and inline
its logic into render_to_cache(). And remove the m_shadow_offset
member variable since it was only needed locally in one place.

Also improve some variable names to make it more understandable what
is going on.
2021-06-16 21:53:10 +02:00
Andreas Kling
d924d93fa2 WindowServer: Fix unnecessary local variable shadowing in WindowFrame 2021-06-16 21:53:10 +02:00
Brian Gianforcaro
8f1e7c5a72 WindowServer: Remove unused AK::InlineLinkedList header includes 2021-06-16 10:40:01 +02:00
Sreelakshmi
aa68c12cfc WindowManager: Close tooltip child_windows of previously active window
This closes the autocomplete_box used in applications like GML
Playground and HackStudio when the user switches focus to a new window.
2021-06-12 23:54:08 +04:30
Andreas Kling
0a98964600 WindowServer+LibGUI: Make window creation asynchronous :^)
Let clients manage their own window ID's. If you try to create a new
window with an existing ID, WindowServer will simply disconnect you
for misbehaving.

This removes the need for window creation to be synchronous, which
means that most GUI applications can now batch their entire GUI
initialization sequence without having to block waiting for responses.
2021-06-12 12:01:54 +02:00
Marcus Nilsson
2f7dc29ab7 LibGUI/WindowServer: Add set_maximized IPC call
Add an IPC call to enable the client to manually maximize it's own
window.
2021-06-09 22:58:10 +02:00
Ali Mohammad Pur
7ac196974d Everywhere: Replace Vector<T*> with nonnull entries with Vector<T&> 2021-06-08 19:14:24 +02:00
Andreas Kling
cb295ab644 WindowServer+Magnifier: Make Magnifier buttery smooth :^)
This patch moves the magnifier rect computation over to the server side
to ensure that the mouse cursor position and the screen image never get
out of sync.
2021-06-07 10:22:25 +02:00
Eugene Barnett
4ef85de9dc WindowServer: Add a GetDesktopDisplayScale IPC request
Tells you which scale factor is configured in window manager.
2021-06-06 15:56:43 +02:00
Tom
2c8309c841 WindowServer: Simplify determining transparent/opaque occlusions
By moving the logic to determine what window areas (shadow, frame,
content) into WindowFrame::opaque/transparent_render_rects we can
simplify the occlusion calculation and properly handle more
arbitrary opaque/transparent areas.

This also solves the problem where we would render the entire
window frame as transparency only because the frame had a window
shadow.
2021-06-06 09:37:27 +01:00
Max Wipfli
bc8d16ad28 Everywhere: Replace ctype.h to avoid narrowing conversions
This replaces ctype.h with CharacterType.h everywhere I could find
issues with narrowing conversions. While using it will probably make
sense almost everywhere in the future, the most critical places should
have been addressed.
2021-06-03 13:31:46 +02:00
Brian Gianforcaro
d0dbb014a0 WindowServer: Switch Window to IntrusiveList from InlineLinkedList
Another small step towards unifying IntrusiveList / InlineLinkedList.
2021-06-03 13:27:40 +02:00
Matthew Jones
0ff09d4f74 WindowServer: Add sanity checks to create_window IPC 2021-06-03 08:27:57 +02:00
Matthew Jones
b0682a73ee WindowServer: Position popup menu with offset of 1 pixel 2021-06-03 08:21:01 +02:00
Matthew Jones
ea4116f5bd LibGUI+LibGfx+WindowServer: Sanity check window size dimensions
Previous to this commit, if a `Window` wanted to set its width or height
greater than `INT16_MAX` (32768), both the application owning the Window
and the WindowServer would crash.

The root of this issue is that `size_would_overflow` check in `Bitmap`
has checks for `INT16_MAX`, and `Window.cpp:786` that is called by
`Gfx::Bitmap::create_with_anonymous_buffer` would get null back, then
causing a chain of events resulting in crashes.

Crashes can still occur but with `VERIFY` and `did_misbehave` the
causes of the crash can be more readily identified.
2021-06-02 23:59:57 +01:00
Gunnar Beutner
b5778675a5 WindowServer: Use RefPtr instead of raw pointers
Now that we have static initializers and destructors we can use
RefPtr here.
2021-06-02 18:08:11 +02:00
Gunnar Beutner
cdb070cdfb WindowServer: Don't crash when we can't allocate a bitmap
When the client specifies an absurdly large window size
render_to_cache() fails to allocate a bitmap and crashes.

Refs #7688.
2021-06-02 10:17:42 +01:00
Matthew Jones
33eb9a6ddc WindowServer: Use user-defined background color, if defined
Use the configured desktop background color, if defined, otherwise
default to the current theme's background color. If a user chooses
a background color via "desktop settings", then this new color
will always be used.

Switching themes will delete the user-defined background color, so
the background color resets to the theme's defined color.
2021-06-02 09:40:53 +02:00
Jean-Baptiste Boric
e4394b1605 LibGfx: Use anonymous buffer instead of raw anon_fd for Gfx::Bitmap
Instead of using a low-level, proprietary API inside LibGfx, let's use
Core::AnonymousBuffer which already abstracts anon_fd and offers a
higher-level API too.
2021-05-24 13:31:01 +02:00
Andreas Kling
c9e849a968 LibCore: Make all processes opt out of InspectorServer by default
This functionality, while neat, isn't really something you need enabled
all the time. Let's make it opt-in instead. Pass MakeInspectable::Yes
to the Core::EventLoop constructor if you want your program to become
inspectable.
2021-05-22 23:30:40 +02:00
Andreas Kling
b5d73c834f Userland: Rename LibThread => LibThreading
Also rename the "LibThread" namespace to "Threading"
2021-05-22 18:54:22 +02:00
Andreas Kling
636c43db6c WindowServer: Notify window-less clients about theme/font changes 2021-05-22 10:21:52 +02:00
Andreas Kling
59fd1f40ce WindowServer: Store system font queries in WindowServer.ini :^)
Changes to the system font settings are now persisted in /etc.
Note that you still need to restart the system for changes to fully
apply in all programs.
2021-05-21 20:15:51 +02:00
Andreas Kling
c778130d63 WindowServer+LibGUI: Add an IPC API to change the current system fonts
This patch adds a set_system_fonts() IPC API that takes the two main
font queries as parameters. We'll probably expand this with additional
queries when we figure out what they should be.

Note that changing the system fonts on a live system mostly takes
effect in newly launched programs. This is because GUI::Widget will
currently cache a pointer to the Gfx::FontDatabase::default_font()
when first constructed. This is something we'll have to fix somehow.

Also note that the settings are not yet persisted.
2021-05-21 20:15:51 +02:00
Andreas Kling
bb23e61fbf LibGfx+WindowServer: Have WindowServer broadcast system font settings
Instead of everybody getting their system fonts from Gfx::FontDatabase
(where it's all hardcoded), they now get it from WindowServer.

These are then plumbed into the usual Gfx::FontDatabase places so that
the old default_font() and default_fixed_width_font() APIs keep working.
2021-05-21 20:15:51 +02:00
Linus Groh
d60ebbbba6 Revert "Userland: static vs non-static constexpr variables"
This reverts commit 800ea8ea96.

Booting the system no longer worked after these changes.
2021-05-21 10:30:52 +01:00
Lenny Maiorani
800ea8ea96 Userland: static vs non-static constexpr variables
Problem:
- `static` variables consume memory and sometimes are less
  optimizable.
- `static const` variables can be `constexpr`, usually.
- `static` function-local variables require an initialization check
  every time the function is run.

Solution:
- If a global `static` variable is only used in a single function then
  move it into the function and make it non-`static` and `constexpr`.
- Make all global `static` variables `constexpr` instead of `const`.
- Change function-local `static const[expr]` variables to be just
  `constexpr`.
2021-05-21 10:07:06 +01:00
Andreas Kling
ec8363aec3 WindowServer+LibGUI: Make client/server greeting faster
Instead of doing a full IPC round-trip for the client and server to
greet each other upon connecting, the server now automatically sends
a "fast_greet" message when a client connects.

The client simply waits for that message to arrive before proceeding.
(Waiting is necessary since LibGUI relies on the palette information
included in the greeting.)
2021-05-20 22:12:42 +02:00
Andreas Kling
6a012ad79f LibGfx: Remove Gfx::FontDatabase::default_bold_font()
Instead use default_font().bold_variant() in cases where we want a bold
variant of the default font. :^)
2021-05-20 20:55:29 +02:00
Andreas Kling
93ef661914 WindowServer+DisplaySettings: Remove the weird "simple" wallpaper mode
Painting the wallpaper at 100% scale in the top left corner is a weird
mode and I don't think we need it. :^)
2021-05-20 17:52:38 +02:00
Andreas Kling
5f342c41b9 WindowServer: Don't attempt to make WindowServer inspectable 2021-05-17 23:32:37 +02:00
Andreas Kling
5d0c3bd564 WindowServer: Add Menu::is_open() to improve readability
"menu.is_open()" instead of "MenuManager::the().is_open(menu)"
2021-05-17 23:28:15 +02:00
Andreas Kling
7e799529b9 WindowServer+LibGUI: Make menubar allocation asynchronous
Same as with menu allocation, move menubar ID management to the client
side, removing more IPC stalls during application startup.
2021-05-17 13:33:41 +02:00
Andreas Kling
baab0a5bef WindowServer+LibGUI: Make menu allocation asynchronous
This was only synchronous since WindowServer managed the ID allocation.
Doing this on the client side instead allows us to make create_menu()
an asynchronous IPC call, removing a bunch of IPC stalls during
application startup.
2021-05-17 13:33:41 +02:00
Andreas Kling
2083d1a3d6 WindowServer: Ignore window base size in aspect ratio enforcement
This makes windows with an aspect ratio behave more naturally if they
also have a base size (e.g from the main widget being a GUI::Frame.)
2021-05-17 12:01:17 +02:00
Andreas Kling
31d4bcf5bf Userland: Tighten a *lot* of pledges! :^)
Since applications using Core::EventLoop no longer need to create a
socket in /tmp/rpc/, and also don't need to listen for incoming
connections on this socket, we can remove a whole bunch of pledges!
2021-05-13 23:28:40 +02:00
Linus Groh
9a27ef6523 WindowServer: Re-render window frame when setting unresponsive status
Otherwise "(not responding)" would not appear in the window title until
the window is moved/resized.
2021-05-12 22:51:56 +01:00
Valtteri Koskivuori
4864ef9440 WindowServer: Add Optional<Gfx::IntRect> argument to get_screen_bitmap()
This way, we can optionally specify a region of the display to capture.
Defaults to entire screen if no rectangle is given.
2021-05-11 10:18:29 +01:00
Andreas Kling
bfeacb5728 WindowServer+Taskbar: Make all the IPC used by Taskbar asynchronous 2021-05-10 12:26:35 +02:00
Andreas Kling
11dc790d69 WindowServer: Make set_background_color and set_wallpaper_mode async
Both of these were already used asynchonrously by GUI::Desktop.
2021-05-10 12:21:42 +02:00
Andreas Kling
b8411d1ef6 WindowServer: Make dismiss_menu() an asynchronous IPC call
This was already being used asynchronously by LibGUI, which meant that
WindowServer would generate a response, and the client would ignore it.
2021-05-10 12:20:28 +02:00
Andreas Kling
f556bd1045 WindowServer: Make popup_menu() an asynchronous IPC call
This was already being used asynchronously by LibGUI, which meant that
WindowServer would generate a response, and the client would ignore it.

This patch simplifies the WindowServer side so it no longer generates
the unnecessary response.
2021-05-10 12:20:28 +02:00
Andreas Kling
8684fca9df WindowServer+LibGUI: Make "move window to front" asynchronous 2021-05-10 12:20:28 +02:00
Andreas Kling
fb93535419 WindowServer+LibGUI: Make menu and menubar teardown asynchronous
Clients don't need to wait for WindowServer to tear down a menu or
menubar before continuing.
2021-05-10 11:53:26 +02:00
Andreas Kling
634e652b6c WindowServer: Add "Move" action to window menus
This can be used to initiate a window move. It's only enabled while
the window is normal (not minimized, maximized or fullscreen.)
2021-05-10 09:06:37 +02:00
Andreas Kling
2bc3cc4cab WindowServer: Add separator above "Close" in window menus 2021-05-10 08:43:44 +02:00
Andreas Kling
353a831c8c WindowServer: Compute final window title before passing to WM clients
We were not substituting the window modified marker ("[*]") in the
title strings we were sending to WM clients. This caused the Taskbar
to show pre-substitution window titles for the Text Editor application.

This patch moves the window title resolution to Window::compute_title()
which is then used throughout.
2021-05-10 00:02:05 +02:00
Andreas Kling
1f24ab91f2 WindowServer: Notify WM clients when a window's modified state changes
Also update the window switcher for good measure. The window switcher
doesn't visualize this information at the moment, but we generally do
this when any window state changes.
2021-05-09 23:59:35 +02:00
Andreas Kling
a47d576e94 WindowServer: Tweak width/height of automatic window tile rects
The resulting window rects when snapping to some edges/corners were
a bit lopsided. This patch makes them symmetrical. :^)
2021-05-09 21:48:38 +02:00
Andreas Kling
5497b7a718 WindowServer: Tweak spacing above maximized windows
Nudge maximized windows 1px upwards. This prevents the outer window
border from showing up above the title bar.
2021-05-09 21:48:38 +02:00
Andreas Kling
5aa9f128fc WindowServer: Simplify the way we update items in the window menu
Instead of trying to update only the little bit that changes, let's
have a function that updates all the window menu items in one go.

It's just a couple of string and boolean assignment, and the real
cost is performing the subsequent menu redraw, which remains the same.
2021-05-09 21:48:38 +02:00
Andreas Kling
c53e937014 WindowServer: Constrain popup menu Y position within screen rect
This fixes an issue where large popup menus would open upwards despite
there not being enough space for that.
2021-05-09 15:47:21 +02:00
Andreas Kling
4c6e3d0c59 WindowServer: Fix a handful of clang-tidy warnings in the menu code
Some avoidable signed/unsigned mismatch, String move construction,
and functions that can be static constexpr.
2021-05-09 15:47:21 +02:00
Eric Butler
5d14636b95 WindowServer: Open window menu on Alt+Space
Adds a keyboard shortcut Alt+Space that opens the window menu.
2021-05-09 15:38:32 +02:00
Eric Butler
967cd6afd2 WindowServer: Select last menu item when up key pressed if no selection
When a menu is first opened and has no selected item, pressing the "up"
key now selects the last menu item instead of the first.
2021-05-09 15:38:32 +02:00
Andreas Kling
5007d7bb38 WindowServer: Don't ignore MouseMove events for pressed window buttons
Without this change, window buttons would get stuck in the "pressed"
state as long as the left mouse button was pressed, even if you moved
the mouse cursor out of the button rect.
2021-05-09 10:34:40 +02:00
Andreas Kling
9d8aa2a57a Taskbar+LibGUI+WindowServer: Shrink taskbar by one pixel
Make the taskbar 27 pixels tall instead of 28. This makes the button
icons and applets vertically centered.

On a related note, this required touching *way* too many places..
2021-05-09 00:11:37 +02:00
Itamar
8a01167c7d AK: Add missing GenericTraits<NonnullRefPtr>
This enables us to use keys of type NonnullRefPtr in HashMaps and
HashTables.

This commit also includes fixes in various places that used
HashMap<T, NonnullRefPtr<U>>::get() and expected to get an
Optional<NonnullRefPtr<U>> and now get an Optional<U*>.
2021-05-08 18:10:56 +02:00
Andreas Kling
f3091d89aa WindowServer: Don't let clients start resize of non-resizable windows
This came up in #6886. If resizing has been disabled for a window,
we shouldn't let clients bypass this via start_window_resize().
2021-05-06 12:09:03 +02:00
Gunnar Beutner
a3baf06549 WindowServer: Ignore mouse clicks we're not handling
This ignores unhandled mouse clicks for the window buttons. Right now
right-clicking on the window buttons animates them as if some action
were to occur when the mouse button is released.
2021-05-04 08:40:00 +02:00
Andreas Kling
1ee31981da WindowServer: Close any open menus when starting window move/resize 2021-05-03 23:13:02 +02:00
Andreas Kling
1aa56f0129 WindowServer+LibGUI: Make much of window construction asynchronous
Most of the IPC that happens between clients and WindowServer when
creating and configuring windows can be asynchronous. This further
reduces the amount of ping-ponging played during application startup.
2021-05-03 21:56:19 +02:00
Andreas Kling
a8a899adbf WindowServer+LibGUI: Make much of menu construction asynchronous
Creating a menu/menubar needs to be synchronous because we need the
ID from the response, but adding stuff *to* menus (and adding menus
to menubars, and menubars to windows) can all be asynchronous.

This dramatically reduces the amount of IPC ping-pong played by
each GUI application during startup.

I measured how long it takes TextEditor to enter the main event loop
and it's over 10% faster here. (Down from ~86ms to ~74ms)
2021-05-03 21:56:13 +02:00
Gunnar Beutner
9e22e9ce88 Userland: Use snake case names in .ipc files
This updates all .ipc files to have snake case names for IPC methods.
2021-05-03 21:14:40 +02:00
Gunnar Beutner
5bb79ea0a7 Userland: Update IPC calls to use proxies
This updates all existing code to use the auto-generated client
methods instead of post_message/send_sync.
2021-05-03 21:14:40 +02:00
Gunnar Beutner
78803ce384 Userland: Split IPC endpoints into proxies and stubs
This enables support for automatically generating client methods.
With this added the user gets code completion support for all
IPC methods which are available on a connection object.
2021-05-03 21:14:06 +02:00
Gunnar Beutner
065040872f Userland: Change IPC funcs to use plain arguments instead of a struct
Instead of having a single overloaded handle method each method gets
its own unique method name now.
2021-05-03 21:14:06 +02:00
Matthew Olsson
88cfaf7bf0 LibGfx: Unify Rect, Point, and Size
This commit unifies methods and method/param names between the above
classes, as well as adds [[nodiscard]] and ALWAYS_INLINE where
appropriate. It also renamed the various move_by methods to
translate_by, as that more closely matches the transformation
terminology.
2021-05-02 22:48:06 +02:00
Andreas Kling
f052a66c5d WindowServer+Base: Show alternate close button for "modified" windows
Windows that are marked as modified will now have another (themable)
close button. This gives an additional visual clue that some action
will be required by the user before the window gets closed.

The default window-close-modified icon is an "X" with "..." underneath,
building on the established use of "..." in menus to signify that
additional user input will be required before an action is completed.
2021-05-02 14:17:49 +02:00
Andreas Kling
819325892a WindowServer: Minor tweaks to Window.h 2021-05-02 13:35:46 +02:00
Andreas Kling
cc6db526a6 WindowServer+LibGUI+Taskbar: Store window progress as Optional<int>
We were previously using the magical constant -1 to signify that a
window had no progress state. Be more explicit an use an Optional. :^)
2021-05-02 10:43:39 +02:00
Gunnar Beutner
889359b6f9 Userland: Make IPC handlers return void if they don't have any outputs 2021-05-02 08:11:38 +02:00
Gunnar Beutner
7cf2839a26 Userland: Get rid of the OwnPtr<...> boilerplate code for IPC handlers 2021-05-02 08:11:38 +02:00
Gunnar Beutner
6cf59b6ae9 Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr 2021-05-01 21:25:06 +02:00
Valtteri Koskivuori
370231c05c Kernel: Expose minor device numbers for keyboard and mouse
A fix for two FIXMEs, and paving the way for multi-keyboard/mouse
support, I guess.
2021-05-01 20:07:11 +02:00
Andreas Kling
20dd5735ce WindowServer+LibGfx: Automatic "modified" markers in window titles
You can now add the string "[*]" to a window title and it will be
replaced with " (*)" if the window is modified, and with "" otherwise.
2021-05-01 19:42:29 +02:00
Andreas Kling
492464f4c1 WindowServer: Add Window "modified" state
This will be used to track which windows contain some kind of unsaved
data that the user may want some help remembering to save. :^)
2021-05-01 19:42:29 +02:00
Andreas Kling
3d4afe7614 Everywhere: "indexes" => "indices"
I've wasted a silly amount of time in the past fretting over which
of these words to use. Let's just choose one and use it everywhere. :^)
2021-04-29 22:23:52 +02:00
Andreas Kling
7ae7170d61 Everywhere: "file name" => "filename" 2021-04-29 22:16:18 +02:00
Andreas Kling
def1f1444a WindowServer: Move configuration file to /etc/WindowServer.ini
This was in the /etc/WindowServer/ directory which had nothing else in
it, so let's just get rid of the directory and move this up one step.
2021-04-29 22:16:18 +02:00
Tom
b88b19272e WindowServer: Fix alpha hit-test accessing out-of-bounds pixels
It's possible that the backing store hasn't been updated yet, so
when performing an alpha hit-test make sure the bitmap actually
contains it.

Fixes #6731
2021-04-29 21:51:41 +02:00
Tom
31c3382577 WindowServer: Use window menu actions when clicking frame buttons
This keeps the minimize/maximize/restore/close implementation
consistent with the window menu actions.
2021-04-28 09:40:34 +02:00
Tom
7345b502ab WindowServer: Don't restore active window if it is minimized
When closing a menu, don't restore the active input to a window that
is now minimized or invisible.

Fixes #6690
2021-04-28 09:40:34 +02:00
Jelle Raaijmakers
2e1320f264 WindowServer: Reevaluate hovered window on window rect change
When a new Window instance is added to the WindowManager, it does not
yet have an updated value for `m_frame->rect()` and we're not checking
if there is a new candidate for the hovered window, which we need to do
since the mouse cursor might hover above the newly opened window.

This fixes both issues: as soon as a Window frame's rect is changed,
ask the WindowManager to reevaluate its hovered window. This takes care
of newly opened windows _and_ windows that are programmatically changed
in size.

This works because when a Window becomes hovered, the WindowManager
sends out an enter event. This event in turn triggers the Window to
evaluate the cursor type under the mouse position and to update it when
necessary.

Fixes #4809.
2021-04-27 08:58:13 +02:00
sin-ack
62af6cd4f9 IPCCompiler: Remove hardcoded endpoint magic, attempt deux
This patch removes the IPC endpoint numbers that needed to be specified
in the IPC files.  Since the string hash is a (hopefully) collision free
number that depends on the name of the endpoint, we now use that
instead. :^)

Additionally, endpoint magic is now treated as a u32, because endpoint
numbers were never negative anyway.

For cases where the endpoint number does have to be hardcoded (a current
case is LookupServer because the endpoint number must be known in LibC),
the syntax has been made more explicit to avoid confusing those
unfamiliar.  To hardcode the endpoint magic, the following syntax is now
used:

endpoint EndpointName [magic=1234]
2021-04-25 14:06:56 +02:00
Andreas Kling
418bc484e4 Revert "IPCCompiler: Use string hashes for IPC endpoint magic"
This reverts commit 59218007a3.
2021-04-25 11:24:12 +02:00
sin-ack
59218007a3 IPCCompiler: Use string hashes for IPC endpoint magic
This patch removes the IPC endpoint numbers that needed to be specified
in the IPC files.  Since the string hash is a (hopefully) collision free
number that depends on the name of the endpoint, we now use that
instead. :^)
2021-04-25 09:29:49 +02:00
Andreas Kling
b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
d342e9608c WindowServer: Add missing <AK/Debug.h> include and use dbgln_if() 2021-04-21 23:49:01 +02:00
Conor Byrne
88ecfa164a LibGUI+WindowServer: Add WM_SuperKeyPressed event
This commit adds an event called WM_SuperKeyPressed which is sent to all
windows via WindowManagerServerConnection.
The event is fired from WindowManager when the super key is pressed,
which is the windows key on most keyboards :)
2021-04-19 20:03:25 +02:00
Maciej Zygmanowski
136f6fb7c8 WindowServer: Use VERIFY instead of assert in scale factor check 2021-04-19 17:30:07 +02:00
Andreas Kling
12546259ff Everywhere: Rename title_bar => titlebar 2021-04-18 16:35:18 +02:00
Andreas Kling
b937ebd121 WindowServer: Make MenuItemActivated IPC message pass identifier as u32
This is consistent with the actual storage type.
2021-04-17 22:26:58 +02:00
Andreas Kling
ec6debb46f WindowServer: Don't "enter" menu item when hovering over a separator
Since menu separator items don't have an associated identifier,
make sure we don't falsely report that we've enter item 0.

This fixes an issue where hovering over a separator would behave
as if we'd hovered over the first item in the menu wrt sending
MenuItemEntered.
2021-04-17 20:49:53 +02:00
Andreas Kling
ba7e1ca2fb WindowServer+LibGUI: Notify GUI clients about menu item enter/leave
We now send out MenuItemEntered and MenuItemLeft messages to the client
when the user hovers/unhovers menu items.

On the client side, these become GUI::ActionEvent, with one of two
types: ActionEnter or ActionLeave. They are sent to the Application.

This will allow GUI applications to react to these events.
2021-04-17 20:49:53 +02:00
sin-ack
aa56f9a1e0 LibGUI+WindowServer: Separate window manager IPC from regular IPC
With this patch the window manager related functionality is split out
onto a new endpoint pair named WindowManagerServer/Client.  This allows
window manager functionality to be potentially privilege separated in
the future.  To this end, a new client named WMConnectionClient
is used to maintain a window manager connection.  When a process
connects to the endpoint and greets the WindowServer as a window manager
(via Window::make_window_manager(int)), they're subscribed to the events
they requested via the WM event mask.

This patch also removes the hardcoding of the Taskbar WindowType to
receive WM events automatically.  However, being a window manager still
requires having an active window, at the moment.
2021-04-17 13:06:25 +02:00
Linus Groh
ba3bc6fef2 LibGUI+WindowServer: Fix some misaligned CMakeLists.txt SOURCES entries 2021-04-16 21:30:53 +02:00
Nicholas-Baron
73dd293ec4 Everywhere: Add -Wdouble-promotion warning
This warning informs of float-to-double conversions. The best solution
seems to be to do math *either* in 32-bit *or* in 64-bit, and only to
cross over when absolutely necessary.
2021-04-16 19:01:54 +02:00
Linus Groh
e632186c17 WindowServer: Recalculate window rect when toggling menubar
This is important when the window is maximized or tiled (which
recalculate_rect() will both check), as we otherwise create a gap above
the window frame (when hiding the menubar) or push the frame off the
screen (when showing the menubar).
2021-04-16 17:28:05 +02:00
Linus Groh
0aebb9ec62 WindowServer: Replace window menu action magic numbers with enum
This makes it a lot easier to find where the action handling is
happening, just 1, 2, 3, 4 isn't very discoverable. :^)
2021-04-16 17:27:54 +02:00
Andreas Kling
b75d2d36e1 WindowServer: Clean up some of the code around menu item hovering
We were writing to the currently hovered menu item index in a bunch
of places, which made it very confusing to follow how it changes.

Rename Menu::set_hovered_item() to set_hovered_index() and use it
in more places instead of manipulating m_hovered_item_index.
2021-04-15 20:50:24 +02:00
Tom
d10b95622b WindowServer: Fix window shadow rendering glitch
Some small window shadows were missing a small section of the top/bottom
and/or left/right center shadow.
2021-04-15 10:22:04 +02:00
Andreas Kling
a2baab38fd Everywhere: It's now "Foobar", not "FooBar", and not "foo bar"
I hereby declare these to be full nouns that we don't split,
neither by space, nor by underscore:

- Breadcrumbbar
- Coolbar
- Menubar
- Progressbar
- Scrollbar
- Statusbar
- Taskbar
- Toolbar

This patch makes everything consistent by replacing every other variant
of these with the proper one. :^)
2021-04-13 16:58:15 +02:00
Andreas Kling
767bd8cc88 WindowServer: Strip Alt-shortcut marker ('&') when measuring menu texts
We were including these markers when computing the sizes of menus,
causing them to get a little too much padding.
2021-04-12 15:24:17 +02:00
Andreas Kling
19fb62dd15 WindowServer: Alt shortcuts and book title capitalization in menus
Specifically, in window menus. :^)
2021-04-10 10:29:42 +02:00
Andreas Kling
2bac9eb79d WindowServer: Cache internal Alt shortcuts on the Menu object
This way we don't have to recompute the set of shortcut keys every
time we're handling an in-menu keydown event.
2021-04-09 17:08:49 +02:00
Andreas Kling
0fc2651303 WindowServer: Support Alt shortcuts inside menus as well
Menu items can now also have Alt shortcut, and they work the same way
top-level menu Alt shortcuts do. This replaces the previous "type to
search" mechanism we had in menus.
2021-04-09 17:08:49 +02:00
Andreas Kling
2b9bc605d2 LibGfx: Add a Gfx::TextAlignment parameter to Painter::draw_ui_text() 2021-04-09 17:08:49 +02:00
Andreas Kling
b7a25bfaac LibGfx: Adjust parameter order for Painter::draw_ui_text()
Let's put the rect first so it's the same as draw_text().
2021-04-09 17:08:49 +02:00
Andreas Kling
1f4dc670d4 WindowServer: Select first item when opening a menu via Alt shortcut
To make keyboard navigation a little nicer, select the first/top menu
item right away.
2021-04-05 23:15:43 +02:00
Andreas Kling
d80fb6d9c0 WindowServer: Support Alt+Character menu shortcuts :^)
This patch adds support for opening menus via keyboard shortcuts.
Use an ampersand in a menu name to automatically create a keyboard
shortcut (Alt + the character following the ampersand.)

Menus with an Alt shortcut have a small underline under the shortcut
character for discoverability.
2021-04-05 23:15:43 +02:00
Andreas Kling
9b740f218b WindowServer+LibGUI: Notify clients when menus become visible/hidden
This will allow clients to react to these events.
2021-04-05 18:09:04 +02:00
Linus Groh
23b659e9c3 WindowServer: Exclude WindowType::Desktop windows from Super key actions
The desktop window is (and must be) considered resizable by
WindowServer, but none of the Super+<something> key actions should apply
to it (window minimizing/maximizing/tiling).

Fixes #5363.
2021-04-05 17:06:58 +02:00
Dawid Wolosowicz
f7184e967e WindowServer: Make applet area use the same color role as the taskbar
So far the taskbar has been using the "Button" as a color role, despite
rest of the applet area using "Window" color role. Although it all
looked alright on most system themes, it broke for the Nord theme.
2021-04-05 14:30:35 +02:00
Dawid Wolosowicz
863bc35399 WindowServer: Propagate theme change to the applet area
Fixes: #6056
2021-04-04 20:52:39 +02:00
Dawid Wolosowicz
182f9582d2 WindowServer: Use non-translated rect to fill the applet area's store
Fixes #6061
2021-04-04 20:52:39 +02:00
Andreas Kling
0069020e6c WindowServer+LibGUI: Rename WindowType::MenuApplet => Applet 2021-04-04 17:55:50 +02:00
Daniël van de Burgt
a106f852d3
WindowServer+MouseSettings: Add ability to configure double-click speed (#5876)
This adds a double-click speed slider control to the Mouse Settings
panel, and value labels for both the movement speed and double-click
speed sliders.

To allow for updating and persisting the configured double-click
speed through the WindowServer, two IPC calls - `SetDoubleClickSpeed`
and `GetDoubleClickSpeed` - have been added.
2021-04-02 16:08:18 +02:00
Andreas Kling
3e3d196f06 WindowServer: Un-nest MenuManager::handle_mouse_event() a bit 2021-04-02 10:54:50 +02:00
Andreas Kling
ea34ba6fa6 WindowServer+LibGfx: Rename menu_bar => menubar
We had a mix of "menu_bar" and "menubar". Let's just use "menubar"
everywhere since that feels the most natural to write.
2021-03-31 23:38:26 +02:00
Andreas Kling
0e798234c7 WindowServer+LibGfx: Remove code for drawing the old-style menu bar 2021-03-31 23:38:26 +02:00
Andreas Kling
0cd60a28ba WindowServer+LibGUI: Plumb mouse/enter/leave events to applet windows
Since applet windows live in the applet area window, the AppletManager
has to keep track of which applet is hovered and send the appropriate
enter/leave events to the applet windows.

This makes applet tooltips work again. :^)
2021-03-30 23:43:24 +02:00
Andreas Kling
9bbc1c9c93 WindowServer+Taskbar: Show applets in taskbar :^)
WindowServer now collects applet windows into an "applet area" which is
really just a window that a WM (window management) client can position
via IPC.

This is rather hackish, and I think we should come up with a better
architecture eventually, but this brings back the missing applets since
the global menu where they used to live is gone.
2021-03-30 23:43:24 +02:00
Andreas Kling
6d913db9fe WindowServer: Install WindowServer headers
This is a bit clunky since we really only need WindowType.h and don't
really want to consider any other headers "public" but this is just
to make the SDL port build again now that LibGUI includes WindowType.h
from WindowServer.

Long term we should probably figure out a way to only install "API"
headers from libraries.
2021-03-30 20:20:32 +02:00
Andreas Kling
50a8e0e495 LibGUI+WindowServer: Keep canonical WindowType enum in WindowServer
Having the same enum in two places was annoying. Let's just "using"
the WindowServer::WindowType enum into the GUI namespace.
2021-03-29 22:39:18 +02:00
Tom
b8f462a78b WindowServer: Add menu item fade-out animation upon activation 2021-03-28 20:42:21 +02:00
Tom
7e9c265cc0 WindowManager: Allow disabling window hit testing altogether
This allows us to disable hit testing for transparent windows that
don't use alpha channels.
2021-03-28 20:42:21 +02:00
Andreas Kling
526b4bbfdb WindowServer: Add ability to show/hide window menubars
This patch adds a toggle item to the window menu that controls window
menubar visibility. This is available in all windows with a menu.
2021-03-28 13:40:40 +02:00
Andreas Kling
71a9a14c17 WindowServer: Make Window::event() protected 2021-03-28 11:25:57 +02:00
Andreas Kling
6f45c27d06 WindowServer: Don't call Core::Object::event() directly
To make sure event filters are respected, we should not be calling
event() directly, but rather dispatch_event().
2021-03-28 11:19:18 +02:00
Linus Groh
2fde87e67d WindowServer: Also keep menus open when activated via Ctrl + return key
I see no reason to limit this awesome feature to mouse clicks. :^)
2021-03-27 11:33:41 +01:00
Andreas Kling
d9f8f6a2d0 WindowServer: Add an IPC call for taking a screenshot
This patch adds Messages::WindowServer::GetScreenBitmap. It returns the
currently displayed on-screen bitmap as-is, as a Gfx::ShareableBitmap.
2021-03-26 20:33:23 +01:00
Andreas Kling
ecb0ae9c33 WindowServer: Keep menu open when activating a menu item with Ctrl held
This makes it easy to "try out" different options (like system themes!)
in a menu without having to re-open the menu over and over. :^)
2021-03-26 14:45:15 +01:00
Andreas Kling
b31b904ad0 WindowServer: Redraw all menus on system theme change 2021-03-26 14:42:38 +01:00
Andreas Kling
4b6fba1e4c WindowServer+LibGfx: Make menubar menus slightly larger
Also make sure the left/right padding is equally large.
2021-03-26 14:25:37 +01:00
Linus Groh
b220c89c5c WindowServer: Adjust position of flipped submenus by menu item height
Fixes #5950.
2021-03-26 09:25:22 +01:00
Linus Groh
8461100bf7 WindowServer: Add clip rect to menubar painter
Fixes #5951.
2021-03-26 09:25:22 +01:00
Andreas Kling
6203a4a2e9 WindowServer: Remove unused Menu->MenuBar link and "title font"
We kept a backpointer from the Menu to its containing MenuBar, but it
was not used for anything so let's remove it.

Since all menus have the same font now, there's no need to track a
separate "title font".
2021-03-26 09:12:32 +01:00
Andreas Kling
dfb81242f3 WindowServer: Redraw window menubars when moving with arrow keys
Also, make sure we don't draw a menu in hovered state while another
menu is open.

Fixes #5949.
2021-03-26 08:59:32 +01:00
Andreas Kling
6ae174f80a WindowServer: Remove some leftover unused menubar things 2021-03-26 08:54:33 +01:00
Andreas Kling
e9db10e3a9 WindowServer+LibGUI: Remove the global menubar :^)
This leaves menu applets running but invisible, and that's a regression
we need to take care of obviously. But not today, because it's getting
too late.
2021-03-25 23:27:11 +01:00
Andreas Kling
1108c41790 WindowServer: Don't fill the active menubar menu with selection color 2021-03-25 23:19:57 +01:00
Andreas Kling
327866520a WindowServer: Remove "system menu" concept from WindowServer 2021-03-25 23:08:34 +01:00
Andreas Kling
fc84076f18 WindowServer: Remove SetApplicationMenubar IPC message 2021-03-25 22:14:09 +01:00
Andreas Kling
fcc8e3484f WindowServer: Remove the global app menu
The SetApplicationMenu IPC message is still there, since we also need
to clean up all of the client code before we can remove that.
2021-03-25 22:14:09 +01:00
Andreas Kling
05cc7d69ac WindowServer: Tweak the look of menus
Paint menus with a flatter outline instead of giving them the regular
window border.
2021-03-25 22:14:09 +01:00
Andreas Kling
e76771bfad WindowServer+LibGfx: Show menus in windows! :^)
This patch begins the transition away from the global menu towards
per-window menus instead.

The global menu looks neat, but has always felt clunky, and there
are a number of usability problems with it, especially in programs
with multiple windows.

You can now call GUI::Window::set_menubar() to add a menubar to
your window. It will be specific to that one window only.
2021-03-25 22:14:09 +01:00
Andreas Kling
e0f32626bc LibGfx: Rename 32-bit BitmapFormats to BGRA8888 and BGRx888x
The previous names (RGBA32 and RGB32) were misleading since that's not
the actual byte order in memory. The new names reflect exactly how the
color values get laid out in bitmap data.
2021-03-16 11:50:03 +01:00
Andreas Kling
ef1e5db1d0 Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)
Good-bye LogStream. Long live AK::Format!
2021-03-12 17:29:37 +01:00
thankyouverycool
142ca4b818 WindowServer+LibGfx: Enumerate Disallow cursor 2021-03-12 09:59:03 +01:00
Andreas Kling
6e2a29d038 WindowServer: Don't open system menu on super key press while dragging 2021-03-11 19:00:24 +01:00
Andreas Kling
38f11cc1ba Everywhere: Rename "logo" key to "super" key
This seems to be the most common way to refer to this key, so let's
call it what people actually call it.
2021-03-11 18:55:16 +01:00
Tom
c73dfe5bf6 WindowServer: Mark screen dirty when changing highlighted window
Because the z-order changes we not only need to recompute occlusions
but we also need to mark the screen area of the previous and new
highlighted window as dirty.

Fixes #5599
2021-03-03 08:20:11 +01:00
Tom
87c1b1a25d WindowServer: Use active shadow for highlighted window
If we're switching through windows we should also use the active
shadow for the highlighted window.
2021-03-03 08:20:11 +01:00
Tom
c57d719d62 WindowServer: Prepare dirty rects if only the frame was invalidated 2021-03-03 08:20:11 +01:00
AnotherTest
857cdee0d0 AK: Make dbgln_if() avoid evaluating the arguments when disabled
Naturally, this makes the `enabled` flag on dbgln() obsolete.
2021-02-24 13:07:28 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Tom
b4c0314f1d WindowServer: Don't close context menus when hovering over menu bar 2021-02-22 09:09:26 +01:00
Tom
35363a972a WindowServer: Reset menu position when opened by the menu bar
Also, only mark the menu bar item as opened if a menu was actually
opened through the menu bar.

These changes allow a menu to be used both in the menu bar as well
as a context menu.

Fixes #5469
2021-02-22 09:09:26 +01:00
Tom
2d29bfc89e WindowServer: Re-evaluate the mouse cursor when alpha hit-testing
A window repaint may change the alpha value, resulting in a different
hit test outcome. In those cases, re-evaluate the cursor hit testing
after a window was painted, and update the cursor if needed.
2021-02-21 22:34:00 +01:00
Tom
1c31bcb24e WindowServer: Allow changing frameless state after a window is created 2021-02-21 10:33:28 +01:00
Tom
101c6b01ed WindowServer: Improve small tooltips/windows shadows a bit
This fixes some artifacts with very small tooltip windows.
2021-02-20 22:28:11 +01:00
Sahan Fernando
e920c74cae WindowServer: Restore cursor when marking window as responsive 2021-02-19 20:30:25 +01:00
Tom
06ee8c5aa8 WindowServer: Ignore other button presses while moving/resizing windows
Fixes #5334
2021-02-18 07:45:44 +01:00
Tom
6af4d35e8e WindowServer: Apply the backing bitmap's scale when alpha hit-testing
Fixes #5390
2021-02-18 07:45:22 +01:00
Andreas Kling
c4438d6fd4 WindowServer: Unbreak "pick new active window" algorithm
We lost the ability to pick a suitable new active window when I added
the support for tool windows.
2021-02-17 16:52:08 +01:00
Andreas Kling
11c8596ad3 WindowServer+LibGUI+LibGfx: Add WindowType::ToolWindow
Tool windows are secondary windows with a smaller title bar. The sit on
the layer above normal windows, and cannot be minimized.

These are intended for complex yet non-modal interactions with the
content of a primary window, such as find/replace windows, property
windows, etc.
2021-02-16 16:26:29 +01:00
Nick Vella
15c1f7a40d WindowServer, LibGUI: Variable minimum window sizes
Minimum window size can now be customised and set at runtime via the
SetWindowMinimumSize WindowServer message and the set_minimum_size
LibGUI::Window method. The default minimum size remains at 50x50.

Some behind-the-scenes mechanics had to be added to LibGUI::Window to
ensure that the minimum size is remembered if set before the window is
shown. WindowServer sends a resize event to the client if it requests a
size on create that's smaller than it's minimum size.
2021-02-16 15:46:03 +01:00
Tom
d590e0c946 WindowServer: Add support for alpha channel based hit testing
This enables implementing non-rectangular window shapes, including
non-rectangular window frames.
2021-02-15 23:07:49 +01:00
Jean-Baptiste Boric
e616cb35ba WindowManager: Fix default menu item on key down
This fixes the key down behavior on Terminal's Edit menu, which tried
to hover the disabled menu item Copy if there was nothing selected.
2021-02-15 19:37:14 +01:00
Jean-Baptiste Boric
f8cb068354 WindowManager: Select top-level menus with left/right keys 2021-02-15 19:37:14 +01:00
Jean-Baptiste Boric
7ee6c66ee9 WindowManager: Make the Logo key open the system menu 2021-02-15 19:37:14 +01:00
Tom
be48a89b35 WindowServer: Fix double click handling while using cursor tracking
We need to first deliver the mouse event and possibly the double click
event and record these facts. Then, we need to iterate all global
tracking listeners and deliver the mouse event (but not the double
click event) to any such listener, unless they already had these
events delivered.

Fixes #4703
2021-02-15 11:03:49 +01:00
Tom
0138f13bfe WindowServer: Improvements to support alpha channel in window frames
This fixes some issues handling the alpha channel that may be present
in rendered window frames.

Fixes #5303
2021-02-13 00:39:33 +01:00
Tom
7e06afb822 WindowServer: Recompute occlusions when changing window's alpha channel
Fixes #4845
2021-02-12 08:57:42 +01:00
Tom
cf1c159ed5 WindowServer: Allow different shadows for active/inactive windows
Also allow specifying different shadows for the task and menu bar.
2021-02-11 23:36:11 +01:00
Linus Groh
0304ab3e67 WindowServer: Fix compositing of fullscreen window
I honestly don't know the internals of all this and what exactly is
going on, but this fixes compositing of the fullscreen window. By trial
and error I found that specifically m_invalidated_all needs to be set to
false, so it's probably different behaviour in prepare_dirty_rects(),
which depends on that...
Either way, the code composing all windows in non-fullscreen mode calls
Window::clear_dirty_rects() for each, so not doing that for the fullscreen
window as well seems like an oversight.

Fixes #4810.
2021-02-11 13:12:17 +01:00
Tom
e1333724ea WindowServer: Blit backing bitmap with transparency for hung windows
We should respect the opacity of the window when painting the window
content of a hung application.
2021-02-11 13:11:57 +01:00
Tom
dd0833107f WindowServer: Fix clearing area not covered by backing bitmap
We only cleared the area not covered by the backing bitmap if a
rendering rectangle intersected with the backing bitmap. But because
we are potentially calling the render function many times we need
to always clear the area not covered by the backing bitmap, whether
it intersects or not.

Fixes #5291
2021-02-11 13:11:57 +01:00
Tom
f8d65e57ba WindowServer: Don't re-render the window frame when not needed
Merely moving a window shouldn't require re-rendering the window
frame anymore now that we cache the rendered frame in bitmaps. This
reduces CPU usage significantly when moving windows.
2021-02-10 23:03:22 +01:00
Tom
a807d92a32 WindowServer: Fix switching between shadows and no shadows with themes
We weren't properly handling switching between having a shadow and
not having a shadow when switching themes. This allows an empty string
in the theme configuration for a shadow path, meaning no shadow should
be rendered.
2021-02-10 09:12:49 +01:00
Tom
5d4c4bd372 WindowServer: Occlusion calculation fixes
We didn't properly determine whether a window was fully covered, which
caused some artifacts in certain cases.

Fixes #5283
2021-02-10 09:12:49 +01:00
Tom
964894dee6 WindowServer: Allow specifying different shadows for menus and tooltips
Also update the Redmond 2000 theme to drop shadows more Redmond-like.
2021-02-09 22:27:14 +01:00
Camisul
8c220dee03 WindowServer: Vertically maximize window
Button now can handle middle and right clicks.
Added 2 new handlers in button class: on_right_click for Right mouse
button and on_middle_click for middle mouse button.

Added functionality to vertically maximize window with middle mouse
click on the maximize window button.

Also added a way to vertically maximize window by resizing window
height-wise lower than the maximum window height.
2021-02-09 21:36:11 +01:00
Tom
e1ee59ac9d WindowServer: Recompute occlusions and re-render shadows on theme change
Since theme changes may change geometrics, which are also affected by
window shadows, we need to recompute occlusions as well as re-render
window frames.
2021-02-09 21:33:54 +01:00
Tom
db0149056f WindowServer: Don't render shadow for frameless windows
Fixes CatDog rendering odd square shadow.
2021-02-09 19:18:00 +01:00
Tom
3d374954eb WindowServer: Try harder to avoid re-rendering window shadow
We only really need to re-render the simple window shadow when
the size of the frame changes. So, for all other cases only re-render
the window frame without rendering the shadow.
2021-02-09 18:47:43 +01:00
Tom
0ce4b9d7db WindowServer: Implement simple window shadows
This implements simple window shadows around most windows, including
tooltips. Because this method uses a bitmap for the shadow bits,
it is limited to rectangular window frames. For non-rectangular
window frames we'll need to implement a more sophisticated algorithm.
2021-02-09 18:47:43 +01:00
Tom
15a1d9aa94 WindowServer: Cache rendered window frame in bitmap
This only renders the window frame once until the size of the window
changes, or some other event requires re-rendering. It is rendered
to a temporary bitmap, and then the top and bottom part is stored
in one bitmap as well as the left and right part. This also adds
an opacity setting, allowing it to be rendered with a different
opacity.

This makes it easier to enhance window themes and allows using
arbitrary bitmaps with e.g. alpha channels for e.g. shadows.
2021-02-08 19:02:04 +01:00
Tom
8ff34f96b6 WindowServer: Calculate transparent frame occlusions
If a window frame has transparency, include these areas in the
transparency rendering area so that we can render them flicker-free.
2021-02-08 19:02:04 +01:00
AnotherTest
09a43969ba Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-02-08 18:08:55 +01:00
Ben Wiederhake
7961e09c29 Everywhere: Add semantically-missing includes
For example, FindInFilesWidget.h mentions GUI::TableView, but did not include
it. On the other hand, all source files that include FindInFilesWidget.h
also include TableView.h, so the issue is only cosmetical.
2021-02-08 18:03:57 +01:00
DragonAlex98
885974fc3c
WindowServer: Don't close menu when clicking on item with submenu (#5239)
When clicking on a menu item with a submenu, don't close the menu.
2021-02-07 12:28:42 +01:00
Andreas Kling
1ce03f4f34 LibIPC: Stop sending client ID to clients
The client ID is not useful to normal clients anymore, so stop telling
everyone what their ID is.
2021-02-01 11:32:00 +01:00
Andreas Kling
a5bbe3280d LibGUI+WindowServer: Don't use a WM IPC to initiate own window resize
The WM_* IPC messages are intended for "outsider" window management,
not for a client's own windows. Make a separate StartWindowResize
message for this.

This was the only reason that every IPC client had to know its server
side client ID.
2021-02-01 11:23:54 +01:00
etaIneLp
e625ae1130 WindowManager: Restore a window's geometry when untiling it
Specifically, when untiling it using the Super-{Left,Right} shortcuts

Fixes #5182
2021-01-30 22:59:16 +01:00
Ben Wiederhake
0558c74e30 WindowServer: Constrain geometry label on move/resize to desktop
Fixes #5063.
2021-01-29 22:49:12 +01:00
Ben Wiederhake
cf586311a6 WindowServer: Split double-duty Window::normalize_rect()
This commit:
- merges the two(!) places that defined independently the minimum size of a window.
- splits Window::normalize_rect(), which was originally just a function to apply
  the minimum size requirement, and has taken on the additional job of nudging
  windows back onto the desktop.

This inadvertantly fixes a crash that happens when a malicious program creates a
window of size (0, 0). Now, a window at [0,0 50x50] is created instead.
2021-01-29 22:49:12 +01:00
Ben Wiederhake
79f534ef12 WindowServer: Allow superdrags to hide the titlebar
Fixes #5105.
2021-01-29 22:49:12 +01:00
Ben Wiederhake
e200824125 WindowServer: Count titlebar towards visible/grabbable area
This had lead to some surprising asymmetry at the bottom of the screen.
2021-01-29 22:49:12 +01:00
Ben Wiederhake
3fd5aec187 WindowServer: Properly determine where a window may be
This also fixes weird behavior of WindowManager::desktop_rect().
None of the callers seem to ever expect an empty Rect, so return a non-empty Rect.
2021-01-29 22:49:12 +01:00
Linus Groh
ed703b461b WindowServer: Fix client unresponsiveness detection
This broke in add01b3, where Core::Timer::create_single_shot() was
changed to create a stopped timer. Fix it by actually starting the timer
right away ourselves.

Fixes #5111.
2021-01-25 22:31:22 +01:00
asynts
eea72b9b5c Everywhere: Hook up remaining debug macros to Debug.h. 2021-01-25 09:47:36 +01:00
asynts
8465683dcf Everywhere: Debug macros instead of constexpr.
This was done with the following script:

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/dbgln<debug_([a-z_]+)>/dbgln<\U\1_DEBUG>/' {} \;

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/if constexpr \(debug_([a-z0-9_]+)/if constexpr \(\U\1_DEBUG/' {} \;
2021-01-25 09:47:36 +01:00
asynts
acdcf59a33 Everywhere: Remove unnecessary debug comments.
It would be tempting to uncomment these statements, but that won't work
with the new changes.

This was done with the following commands:

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \;

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-25 09:47:36 +01:00
asynts
1a3a0836c0 Everywhere: Use CMake to generate AK/Debug.h.
This was done with the help of several scripts, I dump them here to
easily find them later:

    awk '/#ifdef/ { print "#cmakedefine01 "$2 }' AK/Debug.h.in

    for debug_macro in $(awk '/#ifdef/ { print $2 }' AK/Debug.h.in)
    do
        find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/#ifdef '$debug_macro'/#if '$debug_macro'/' {} \;
    done

    # Remember to remove WRAPPER_GERNERATOR_DEBUG from the list.
    awk '/#cmake/ { print "set("$2" ON)" }' AK/Debug.h.in
2021-01-25 09:47:36 +01:00
Jean-Baptiste Boric
491a67ddc4 WindowServer: Don't crash if unable to open input peripherals
Seems a bit extreme, other operating systems don't have their graphical
environment crash if there is no keyboard or no mouse.
2021-01-24 22:16:18 +01:00
Ben Wiederhake
e937012870 WindowServer: Make dragging maximized windows up no-op
That's what that piece of logic is probably supposed to be doing.
Let's help it acheive that purpose! Apparently the top of the desktop
(i.e. the menubar) was forgotten, so consider it part of the deadzone.
2021-01-23 08:34:17 +01:00
Ben Wiederhake
a671a5ba7e WindowServer: Prevent moving a window to inaccessible region
This is based on a comment by @tomuta on #4644, and should prevent all future
instances of bugs like #4644.

Disadvantage: The current implementation may generate a lot of WM_WindowRectChanged
events for a listener while bouncing occurs. Feel free to improve this.
2021-01-23 08:34:17 +01:00
Ben Wiederhake
2de471b9f0 WindowServer: Fix many subtle bugs in tiling/maximizing
- Unmaximization/untiling had nearly but not quite code duplication;
  this patch replaces the actual "regrabbing" logic with Rect::set_size_around.
- When undoing maximization/untiling, it used to be possible to to grab a window
  "outside" of its frame, and thus drag it off the screen. This is no longer
  possible. Fixes #4644.
- As a side effect, when untiling from the bottom/left/right, the regrab is now
  a much smoother experience.
- Setting the resize aspect ratio while being tiled now untiles and umaximizes
  the window, as these things are incompatible. Fixes an undocumented bug
  (steps to reproduce: maximize, then set aspect ratio).
- When unmaximizing, spurious WindowLeft events were sent, because that path
  didn't set hovered_window. Fixes an undocumented bug.

Since these things are interwoven, this is all a single commit.
2021-01-23 08:34:17 +01:00
Ben Wiederhake
6a552f0b93 WindowServer: Remember the correct untiled rect
What a silly logic bug! :)
2021-01-23 08:34:17 +01:00
Ben Wiederhake
399908e53c WindowServer: Normalize preferred rect before applying
Previously, SetWindowRect and SetWindowRect could supply basically arbitrary
x and y coordinates. This could happen either due to a malicious or malfunctioning
program, or even due to the auto-centering feature.

This patch also moves the 'normalization' code out of ClientConnection to Window,
where it belongs better.

Fixes #4135.
Fixes #5052.
2021-01-23 08:34:17 +01:00
Nico Weber
345909c009 WindowServer: Don't crash on wallpapers smaller than the desktop with fill mode 'simple'
blit() calls draw_scaled_bitmap() behind the scenes in scaled contexts,
and that doesn't  like src_rect to be outside of the source bitmap's
bounds. Implicitly clip with the source rect, like the non-scaled
codepath already does.

Fixes #5017 even more.
2021-01-23 08:31:41 +01:00
asynts
fb8d3635d9 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-22 22:14:30 +01:00
asynts
24888457d5 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-22 22:14:30 +01:00
Nico Weber
2ec6bbd7a1 LibGfx: Add a draw_scaled_bitmap() variant that takes a FloatRect as src_rect
Consider

    draw_scaled_bitmap({0, 0, 10, 10}, source, {0, 0, 5, 5}).

Imagine wanting to split that up into two calls, like e.g. the
compositor when redrawing the background with damage rects. You really
want to be able to say

    draw_scaled_bitmap({0, 0, 5, 10}, source, {0, 0, 2.5, 5})

but up to now you couldn't. Now you can.

This makes painting very low-res images (such as tile.png) in mode
"stretch" work much better.
2021-01-22 22:13:53 +01:00
Linus Groh
421587c15c Everywhere: Fix typos 2021-01-22 18:41:29 +01:00
Nico Weber
2fe6a313c2 LibGfx: Implement blit_offset() in terms of blit()
It's less code, and blit() already handles scaled painters.

Fixes the window server asserting in highdpi mode with a centered
background image. Part of #5017.
2021-01-22 17:32:44 +01:00
Nico Weber
c98055de75 LibGfx: Remove Painter::blit_scaled() in favor of Painter::draw_scaled_bitmap()
draw_scaled_bitmap() has a clearer API (just source and dest rects --
blit_scaled() took those and scale factors and then ignored width and
height on the source rect and it was less clear what it was supposed to
do), and they do mostly the same thing.

The draw_scaled_bitmap() API takes an IntRect as source rect, so it's
currently not always possible to split a big draw_scaled_bitmap() into
two (or more) smaller draw_scaled_bitmap() calls that do the same thing
-- that'd require FloatRects. The compositor kind of wants this to be
possible, but there's already a FIXME about this not looking quite right
with the previous approach either.

draw_scaled_bitmap() handles transparent sources, so after this change
wallpapers with transparency will be blended instead of copied. But that
seems fine, and if not, the Right Fix for that is to remove the alpha
channel from wallpapers after loading them anyways.

As an added bonus, draw_scaled_bitmap() already handles display scale,
so this fixes window server asserts for background images that are shown
as "stretch" (#5017). The window server still asserts for "tile" and
"offset" for now though.

Calling draw_scaled_bitmap() here exposed a bug in it fixed by #5041.
Before that is merged, this change here will cause smearing on the
background image when moving windows around.
2021-01-22 16:58:41 +01:00
Nico Weber
98637bd549 WindowServer: In HighDPI mode, load high-res window buttons and high-res cursors
Bitmap::load_from_file("foo.png", 2) will now look for "foo-2x.png" and
try load that as a bitmap with scale factor 2 if it exists. If it
doesn't, it falls back to the 1x bitmap as normal.
Only places that know that they'll draw the bitmap to a 2x painter
should pass "2" for the second argument.

Use this new API in WindowServer for loading window buttons and
cursors.

As a testing aid, ctrl-shift-super-i can force HighDPI icons off in
HighDPI mode. Toggling between low-res and high-res icons makes it easy
to see if the high-res version of an icon looks right: It should look
like the low-res version, just less jaggy.

We'll likely have to grow a better API for loading scaled resources, but
for now this suffices.

Things to check:
- `chres 640 480` followed by `chres 640 480 2` followed by
  `chres 640 480`
- window buttons in window context menu (in task bar and on title bar)
  still have low-res icons
- ctrl-shift-super-i in high-res mode toggles sharpness of window
  buttons and of arrow cursorf
- arrow cursor hotspot is still where you'd expect
2021-01-20 10:28:27 +01:00
Nico Weber
5f9c42c404 LibGfx: Give Bitmap a scale factor
Gfx::Bitmap can now store its scale factor. Normally it's 1, but
in high dpi mode it can be 2.

If a Bitmap with a scale factor of 2 is blitted to a Painter with
scale factor of 2, the pixels can be copied over without any resampling.
(When blitting a Bitmap with a scale factor of 1 to a Painter with scale
factor of 2, the Bitmap is painted at twice its width and height at
paint time. Blitting a Bitmap with a scale factor of 2 to a Painter with
scale factor 1 is not supported.)

A Bitmap with scale factor of 2 reports the same width() and height() as
one with scale factor 1. That's important because many places in the
codebase use a bitmap's width() and height() to layout Widgets, and all
widget coordinates are in logical coordinates as well, per
Documentation/HighDPI.md.

Bitmap grows physical_width() / physical_height() to access the actual
pixel size. Update a few callers that work with pixels to call this
instead.

Make Painter's constructor take its scale factor from the target bitmap
that's passed in, and update its various blit() methods to handle
blitting a 2x bitmap to a 2x painter. This allows removing some gnarly
code in Compositor. (In return, put some new gnarly code in
LibGfxScaleDemo to preserve behavior there.)

No intended behavior change.
2021-01-20 10:28:27 +01:00
Linus Groh
c6726f331e WindowServer: Rename WallpaperMode::{Scaled => Stretch}
This option was renamed from scaled to stretch in DisplaySettings in
699ba84, but since WindowServer receives a plain string and was not
updated, it wouldn't recognize the new renamed value as a valid option.
Turns out sending plain strings via IPC and only mapping them to enum
values on the receiving end is brittle, we should probably update
Desktop::set_wallpaper_mode() to use an enum as well at some point.

Fixes #5006.
2021-01-20 09:16:27 +01:00
Nico Weber
1382bbfc57 LibGfx: Make Painter take the scale factor as constructor argument
I want to give Bitmap an intrinsic scale factor and this is a step
in that direction.

No behavior change.
2021-01-17 16:10:21 +01:00
Andreas Kling
1cb44ec5ee Everywhere: Remove more <AK/SharedBuffer.h> includes 2021-01-17 00:04:42 +01:00
Andreas Kling
8a61aba1e5 LibGfx+LibGUI: Make Gfx::ShareableBitmap transmit indexed palettes 2021-01-16 23:58:47 +01:00
Andreas Kling
04f95f9160 WindowServer+LibGUI: Pass the system theme using Core::AnonymousBuffer
This was the last remaining user of shbufs in WindowServer, and so
WindowServer no longer pledges "shared_buffer" :^)
2021-01-16 17:20:53 +01:00
Andreas Kling
01c2480eb3 Kernel+LibC+WindowServer: Remove unused thread/process boost mechanism
The priority boosting mechanism has been broken for a very long time.
Let's remove it from the codebase and we can bring it back the day
someone feels like implementing it in a working way. :^)
2021-01-16 14:52:04 +01:00
Andreas Kling
c71807a3fc Everywhere: Convert a handful of String::format() => formatted() 2021-01-16 14:52:04 +01:00
Andreas Kling
4277be356a WindowServer+LibGUI: Send menu item icons as Gfx::ShareableBitmap 2021-01-16 11:26:53 +01:00
Andreas Kling
ab0dad5ea2 WindowServer+LibGUI: Pass drag&drop bitmaps via Gfx::ShareableBitmap
This makes them backed by anonymous files instead of shbufs and also
simplifies the code significantly on both client and server side.
2021-01-16 11:26:53 +01:00
Nick Vella
fcf50af53d WindowServer, LibGUI: RefreshSystemTheme implementation
Adds a mechanism through which windowing clients can re-request an
UpdateSystemTheme message. This is currently used in SystemMenu's
ShutdownDialog to refresh it's theme when the dialog is instantiated.
2021-01-16 09:09:04 +01:00
Andreas Kling
333366a99d WindowServer+Taskbar: Send WM icon updates as Gfx::ShareableBitmap
Window icons in Taskbar were previously received in WM events with
shbuf ID's. Now that Gfx::ShareableBitmap is backed by anonymous files,
we can easily switch to using those.
2021-01-15 23:24:07 +01:00
Nico Weber
63ac9462ad WindowServer: Add a "scale" parameter to the SetResolution message and plumb it through
Now, `chres 640 480 2` can set the UI to HighDPI 640x480 at runtime. A
real GUI for changing the display factor will come later.

(`chres 640 480 2` followed by `chres 1280 960` is very fast since
we don't have to re-allocate the framebuffer since both modes use
the exact same number of physical pixels.)
2021-01-15 22:05:08 +01:00
Nico Weber
248d75e13b WindowServer: Don't reallocate the cursor back bitmap all the time in HighDPI mode
It's in efficient, and it also meant we wouldn't reallocate a bigger
backing bitmap in a lowdpi->highdpi transition, leading to minor drawing
glitches after such a transition.

(Whoops!)
2021-01-15 22:05:08 +01:00
Nico Weber
e87b8a79ed WindowServer: Make HighDPI aware
Almost all logic stays in "logical" (unscaled coordinates), which
means the patch is small and things like DnD, window moving and
resizing, menu handling, menuapplets, etc all work without changes.

Screen knows about phyiscal coordinates and mouse handling internally is
in physical coordinates (so that two 1 pixel movements in succession can
translate to one 1 logical coordinate mouse movement -- only a single
event is sent in this case, on the 2nd moved pixel).

Compositor also knows about physical pixels for its backbuffers. This is
a temporary state -- in a follow-up, I'll try to let Bitmaps know about
their intrinsic scale, then Compositor won't have to know about pixels
any longer. Most of Compositor's logic stays in view units, just
blitting to and from back buffers and the cursor save buffer has to be
done in pixels. The back buffer Painter gets a scale applied which
transparently handles all drawing. (But since the backbuffer and cursor
save buffer are also HighDPI, they currently need to be drawn using a
hack temporary unscaled Painter object. This will also go away once
Bitmaps know about their intrinsic scale.)

With this, editing WindowServer.ini to say

  Width=800
  Height=600
  ScaleFactor=2

and booting brings up a fully-functional HighDPI UI.
(Except for minimizing windows, which will crash the window server
until #4932 is merged. And I didn't test the window switcher since the
win-tab shortcut doesn't work on my system.) It's all pixel-scaled,
but it looks pretty decent :^)
2021-01-15 19:10:16 +01:00
Nico Weber
867807fb2b WindowServer: Delete dead set_screen parameter 2021-01-15 19:09:10 +01:00
Andreas Kling
0b0514d46b LibGUI+WindowServer: Use anonymous files for window backing stores :^)
This patch replaces the use of shbufs for GUI::Window backing stores
with the new anonymous files mechanism.

Backing bitmaps are now built on memory allocated with anon_create().
They are passed across the IPC socket as IPC::File. This means that
WindowServer now pledges "recvfd" and graphical clients need to pledge
"sendfd" to work.

To support the cached bitmap swapping optimization on the WindowServer
side, each backing store is assigned an incrementing serial number on
the client side. (This allows us to re-use an already mapped file.)
2021-01-15 13:57:00 +01:00