Commit graph

131 commits

Author SHA1 Message Date
Andreas Kling
faa1a09042 LibGUI: Fix const-correctness issues 2023-02-21 00:54:04 +01:00
Tim Schumacher
82a152b696 LibGfx: Remove try_ prefix from bitmap creation functions
Those don't have any non-try counterpart, so we might as well just omit
it.
2023-01-26 20:24:37 +00:00
Jelle Raaijmakers
634d1e0197 LibGUI+WindowServer: Improve window resizing performance
The old `GUI::Window` resizing behavior created a new backing store for
each resize event (i.e. every visible window size). This caused a lot of
trashing and on my machine, caused up to 25% of CPU time spent in
creating new backing stores.

The new behavior is a bit more sensible:

  * If the window size is shrinking, the backing store is already large
    enough to contain the entire window - so we don't create a new one.

  * If the window size is growing, as soon as the backing store can no
    longer contain the window, it is inflated with a large margin (of an
    arbitrary chosen 64 pixels) in both directions to accommodate some
    leeway in resizing before an even larger backing store is required.

  * When the user stops resizing the window, the backing store is
    resized to the exact dimensions of the window.

For me, this brings the CPU time for creating backing stores down to 0%.
2023-01-17 18:16:02 +01:00
MacDue
c7ab6daf26 LibGUI: Stop duplicating mouse events of cursor tracking widget
Previously we didn't always return when there was an automatic cursor
tracking widget. This meant for certain events e.g. a MouseUp over
the tracking widget, the event would be fired twice on the same widget
(once on `m_automatic_cursor_tracking_widget` then again on
`result.widget` outside the if).

Fixes #16737
2023-01-03 21:25:08 +01:00
thankyouverycool
5b02e6a46b LibGUI: Handle Enter+Leave events for automatic cursor trackers
Previously, automatic cursor tracking widgets consumed all mouse
events but did not update their own hover state while active, meaning
Enter and Leave events were not being dispatched.

Fixes TextEditor's automatic selection scroll timer failing to stop
and start while autotracking. Its manual workaround in mousedown
is no longer needed.
2022-12-26 09:27:19 +01:00
MacDue
27fae78335 Meta+Userland: Pass Gfx::IntSize by value
Just two ints like Gfx::IntPoint.
2022-12-07 11:48:27 +01:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
thankyouverycool
ef7d9c0166 LibGUI: Disallow shortcut propagation in Blocking modals and Popups
This restriction is already present for mouse shortcuts but was
forgotten in the recent key event refactor.
2022-11-19 16:04:42 +01:00
thankyouverycool
3027cf7e99 LibGUI+WindowServer: Remove InputPreemptor concept
This functionality will be superceded by WindowType:Popups
2022-11-19 16:04:42 +01:00
thankyouverycool
5d567565a4 LibGUI+WindowServer: Replace WindowInput{Enter,Leave} Events
with WindowInput{Preempted,Restored} Events and allow Widgets to save
the state of their focus preemption. As of now, only Popups will
preempt input and trigger these events.
2022-11-19 16:04:42 +01:00
thankyouverycool
c88d77361c LibGUI: Allow adding previously constructed menus to Menubar 2022-11-19 11:04:11 +01:00
Zaggy1024
967dfa7956 LibGUI: Handle Action keyboard shortcuts in Widget keydown
Widgets can now prevent shortcut Actions from being called, which
allows text input keydown handlers to override single key shortcuts.
2022-11-14 16:08:11 +00:00
Zaggy1024
8e7c7e0a2a LibGUI: Share code for finding an Action by Shortcut
This moves logic for finding a shortcut on a Window or Widget to
Action::find_action_for_shortcut instead.
2022-11-14 16:08:11 +00:00
Timothy Flynn
0d5209cee6 LibGUI+WindowServer: Allow programatically minimizing windows
The backend methods in WindowServer already exist. This just adds the
IPC plumbing to connect those methods to GUI::Window.
2022-11-02 15:41:19 +00:00
demostanis
63a18aa89e LibGUI+WindowServer: Add Window::set_always_on_top() 2022-10-13 12:37:54 +01:00
Mart G
8202beeb2b WindowServer+LibGUI: Shrink window edge resize hot-spots
The hot-spots for resizing a window by dragging its corner are now
limited to a small area around the actual corner instead of an area with
1/3rd the length or width of the window.

The hot-spots to resize a window while holding a modifier key and the
right mouse button are unchanged.
2022-10-11 17:48:48 +02:00
thankyouverycool
7c2edd232d LibGUI: Reset Windows as visible for timer purposes on show()
Fixes scrolling timers failing to fire if a ComboBox window
had previously become occluded.
2022-09-22 21:37:26 +02:00
thankyouverycool
463aff827e LibGUI+WindowServer: Notify Windows on input preemption
Previously Menus set themselves as active input solely to make
sure CaptureInput modals would close, but this is a functional
half-truth. Menus don't actually use the active input role; they
preempt normal Windows during event handling instead.

Now the active input window is notified on preemption and Menus
can remain outside the active input concept. This lets us make
more granular choices about modal behavior. For now, the only
thing clients care about is menu preemption on popup.

Fixes windows which close on changes to active input closing
on their own context menus.
2022-09-08 23:21:54 +01:00
thankyouverycool
4c7f95e2f8 LibGUI+WindowServer+Apps: Replace Accessory Windows
with the CaptureInput WindowMode. This mode will serve the same
function as accessories: redirecting input while allowing parent
windows to remain active.
2022-08-25 13:28:50 +02:00
thankyouverycool
589572cfa4 LibGUI+WindowServer: Introduce WindowModes
Previously, Windows only understood blocking modality: Windows were
either modal, i.e., in a blocking state, or not. Windows could also
be set as Accessories or ToolWindows, attributes which technically
applied modes to their parents but were implemented ad hoc. This patch
redefines these modal effects as WindowModes and sets up some helpers.
This will let us simplify a lot of modal logic in the upcoming patches
and make it easier to build new modal effects in the future.

Windows can now set 1 of 5 modes before reification:
-Modeless:	No modal effect; begins a new modal chain
-Passive:	Window joins its modal chain but has no effect
-RenderAbove:	Window renders above its parent
-CaptureInput:	Window captures the active input role from its parent
-Blocking:	Window blocks all interaction with its modal chain

States like fullscreen and tiling are dynamic and don't alter behavior
in modal chains, so they aren't included.
2022-08-25 13:28:50 +02:00
thankyouverycool
c5dd72ac71 LibGUI: Remember size and position of hidden Windows
And don't reset windowless rects on resize events. Fixes child
windows reappearing at [0,0] and with the wrong dimensions after
being hidden.
2022-08-25 13:28:50 +02:00
thankyouverycool
46d6347035 LibGUI+WindowServer: Initialize minimum window size to zero
And remove unnecessary workarounds to the old limit of {50, 50} and
the cautious but arbitrary limit of {1, 1} for other WindowTypes.
Null rects are already the default when calculating minimum window
size and are the least restrictive but valid value.

Also returns early during minimum size calculations for frameless
windows, and verifies against negative minimum sizes and failure to
disable widget min size before setting a minimum window size. Layout
automatically overrides this setting each relayout otherwise.
2022-08-25 13:28:50 +02:00
Andreas Kling
6548ae8afd LibGUI: Retain the active input tracking widget's cursor
Until the tracking stops, we want to keep displaying the same cursor.
2022-08-16 00:58:26 +02:00
thankyouverycool
5917545633 LibGUI+LibGfx: Let Desktop::the() set widget effects
Scrolling can now be set Coarse or Smooth system-wide, Splitter
knurls and Tab accents toggled on and off, and Menu flashing
disabled.
2022-08-09 12:08:21 +02:00
sin-ack
c70f45ff44 Everywhere: Explicitly specify the size in StringView constructors
This commit moves the length calculations out to be directly on the
StringView users. This is an important step towards the goal of removing
StringView(char const*), as it moves the responsibility of calculating
the size of the string to the user of the StringView (which will prevent
naive uses causing OOB access).
2022-07-12 23:11:35 +02:00
FrHun
80ea141ffe LibGUI: Calculate Window min_size on show 2022-07-04 11:15:40 +02:00
FrHun
5d25956790 LibGUI: Add ability to calculate min_size of Window from content widget 2022-06-29 19:11:13 +01:00
FrHun
603034759f LibGUI: Remove usages of deprecated implicit conversions 2022-06-28 17:52:42 +01:00
Olivier De Cannière
6c202ee4a9 LibGUI: Fix typo in ConnectionToWindowManagerServer 2022-06-01 19:31:34 +02:00
Geordie Hall
737c1c86dc LibGUI: Search for actions with a Shortcut instead of for KeyEvent
Instead of having widget/window/application create a shortcut from a
KeyEvent within their find methods, we'll just pass them a Shortcut
so that the "where to search" logic doesn't need to be duplicated
for different Shortcut types.

It also lets us handle invalid Shortcut rejection at a higher level,
with most things letting the caller be responsible for not searching
for actions with an invalid shortcut.
2022-05-30 00:13:27 +01:00
Andreas Kling
1a38ab0ca1 WindowServer+LibGUI: Notify windows when their maximized state changes
Previously, GUI::Window::is_maximized() had to make a synchronous IPC
request to WindowServer in order to find out if the window was indeed
maximized.

This patch removes the need for synchronous IPC by instead pushing the
maximization state to clients when it changes.

The motivation for this change was that GUI::Statusbar was checking
if the containing window was maximized in its resize_event(), causing
all windows with a statusbar to block on sync IPC *during* resize.
Browser would typically block for ~15 milliseconds here every time
on my machine, continuously during live resize.
2022-04-05 17:45:07 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
circl
eeeaf410fb WindowServer+LibGUI: Expose raw scroll wheel values to applications
This is useful, for instance, in games in which you can switch held
items using the scroll wheel. In order to implement this, they
previously would have to either add a hard-coded division by 4, or look
up your mouse settings to adjust correctly.

This commit adds an MouseEvent.wheel_raw_delta_x() and
MouseEvent.wheel_raw_delta_y().
2022-03-27 01:11:27 +01:00
Itamar
935d023967 Userland: Rename WindowServerConnection=>ConnectionToWindowServer
This was done with CLion's automatic rename feature.
2022-02-25 22:35:12 +01:00
Itamar
af132fdbd1 Userland: Rename WindowManagerServerConnection
Rename WindowManagerServerConnection=>ConnectionToWindowManagerServer.

This was done with CLion's automatic rename feature.
2022-02-25 22:35:12 +01:00
thankyouverycool
aefe3ef539 LibGUI: Allow Windows to set a default return key widget
The default return key widget takes precendence when dispatching
return key events with the exception of focused buttons.
2022-01-26 23:19:54 +01:00
Dmitry Petrov
1662213737 Userland: Add horizontal mouse scroll support 2022-01-20 10:37:52 +01:00
bugreport0
6c049ea4c4 LibGUI+WindowServer: Flash menubar menu when using a keyboard shortcut
Briefly flash the menubar menu containing the keyboard shortcut action
to give the user immediate visual feedback on their interaction with the
system.
2022-01-09 00:54:46 +01:00
Andreas Kling
bde9c2bc65 LibGUI: Add GUI::Window::try_add_menu()
This is a fallible variant of add_menu() that returns ErrorOr.
2021-11-24 13:52:01 +01:00
Andreas Kling
0de33b3d6c LibGfx: Use ErrorOr<T> for Bitmap::try_create()
Another one that was used in a fajillion places.
2021-11-08 00:35:27 +01:00
Andreas Kling
f23f99d51b LibGfx: Use ErrorOr<T> for Bitmap::try_create_with_anonymous_buffer() 2021-11-08 00:35:27 +01:00
Andreas Kling
e2eabb4132 LibCore: Use ErrorOr<T> in Core::AnonymousBuffer 2021-11-08 00:35:27 +01:00
Andreas Kling
60a245b065 LibGUI: Don't ask WindowServer to destroy windows during app teardown
This makes teardown faster since we don't have to wait for responses to
each destroy_window request. It also avoids doing IPC during teardown,
which is a general source of problems.
2021-11-03 19:56:47 +01:00
Marco Cutecchia
116bb4888f LibGUI: Support using a bitmap as override cursor 2021-10-31 12:37:49 +01:00
Andreas Kling
f27d768745 LibGUI: Don't force flush pending paints whenever mouse moves
This patch removes a hack that forced any pending repaints to happen
immediately whenever you moved the mouse over a window.

The purpose of that mechanism was to ensure that quick button presses
still show up visually, and since that is now accomplished via
Widget::repaint(), we no longer need this.
2021-10-23 17:57:05 +02:00
Andreas Kling
24651f854c LibGUI: Add Widget::repaint() to force an immediate repaint
In most situations, Widget::update() is preferable, since that allows us
to coalesce repaints and avoid redundant work, reducing system load.

However, there are some cases where you really want a paint to happen
right away, to make sure that the user has a chance to see a short-lived
visual state.
2021-10-23 17:53:11 +02:00
Timothy Flynn
176155c695 LibGUI+WindowServer: Add option to hide a widow's close button
This allows windows to be closed only programatically, and not from e.g.
the user clicking the X button on the window frame.
2021-10-21 14:45:30 +01:00
Karol Kosek
d91f194ddd LibGUI: Remember the maximized value if a window hasn't been created yet
d0fb511d75 set the maximized window value
in the File Manager before a window was created, which resulted in crash
everytime you tried to open the program that was closed while it was
maximized. ugh

Here we do more-or-less what GUI::Window::set_rect() does, except we
don't add it to the WindowServer::create_window() IPC call.
That's because the Window Server knows nothing about menus at this
point and just assumes they don't need to be visible.
So if we try to maximize the window then, it could be slightly taller
and a titlebar could be hidden.

So even though it looks how it looks like, it does work and it doesn't
show in the startup size, as described in the mentioned commit (the call
is put a few lines before the initial update()). :^)
2021-10-17 21:39:54 +02:00
Karol Kosek
38bc81015b LibGUI: Update the window cursor if it was provided as a bitmap
This condition rejected almost every bitmap cursor change.
2021-09-20 15:59:34 +02:00