Commit Graph

176 Commits

Author SHA1 Message Date
Sebastian Keller
8e664a8cbe iconGrid: Add more possible icon sizes
When selecting the largest possible icon size for restricted vertical or
horizontal space the options for low resolution icons were rather coarse
grained. This could often result in seemingly too small icons being
chosen in the app grid on systems with low vertical resolution, because
the next larger size would exceed the limit by a few pixels.

This adds two more commonly used sizes for application icons to have
some more options with restricted space.

Helps: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2173
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2289>
2022-05-04 20:49:15 +00:00
Florian Müllner
26235bbe54 js: Use (dis)connectObject()
Start using the new methods to simplify signal cleanup. For now,
focus on replacing existing cleanups; in most cases this means
signals connected in the constructor and disconnected on destroy,
but also other cases with a similarly defined lifetime (say: from
show to hide).

This doesn't change signal connections that only exist for a short
time (say: once), handlers that are connected on-demand (say: the
first time a particular method is called), or connections that
aren't tracked (read: disconnected) at all.

We will eventually replace the latter with connectObject() as
well - especially from actor subclasses - but the changeset is
already big enough as-is :-)

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1953>
2022-03-04 14:14:37 +00:00
Sebastian Keller
dff5bef45c iconGrid: Remove unused spring animation code
The spring animation has not been used since 40.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2081>
2022-01-02 16:24:14 +01:00
Florian Müllner
4b4d422c1e iconGrid: Bail out when not on a monitor
There shouldn't be any code that calls zoomOutActor() without
a monitor, but throwing in an early return doesn't hurt.

CID 351285.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1950>
2021-08-13 15:16:54 +02:00
Florian Müllner
30e49cc3ca iconGrid: Disconnect signals on destroy
Otherwise the handler will trip over unset properties on an object
that is being disposed. Avoid the resulting log spam by disconnecting
the handler in question.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1909>
2021-07-08 23:17:01 +00:00
Sebastian Keller
f2db9b52c9 iconGrid: Only use page relative coords for orientation in getDropTarget
The x and y coordinates were both adjusted to be page relative, even
though the icon grid can only scroll in one direction. This was leading
to coordinates outside of the icon grid to be considered part of it and
a wrong drop target to be chosen.

Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3779

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1767>
2021-03-14 18:44:03 +00:00
Jonas Dreßler
d21a0b186e iconGrid: Subclass a C actor for BaseIcon
We create a lot of BaseIcons for the appGrid, one for every app, and for
all of those we have to hop through JS to get the preferred width. That
makes it another obvious target for moving to C, so let's do that.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1755>
2021-03-13 22:13:25 +00:00
Jonas Dreßler
7f99655067 iconGrid: Only animate items when we actually need it
Animating items of the iconGrid involves calling a few more C functions,
which is quite slow. Especially calling ClutterActor.set_easing_delay()
is slow because we override that function in JS to adjust for the
animation slow-down factor. So add a small class variable to make sure
we only animate the icons of the grid when we actually need it.

This makes the average time spent in vfunc_allocate() of the iconGrid go
down to about 0.7 ms.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>
2021-03-03 17:59:16 +00:00
Jonas Dreßler
7771bf4437 iconGrid: Save class variables to local ones
It's quite slow to access class variables in JS, especially when they're
backed by GObject properties. To avoid accessing them in every iteration
when we're looping through the children of iconGrid, store those values
to another variable and reuse that inside the loop.

This shaves off another 0.2 ms from iconGrids vfunc_allocate(), getting
the average time spent in that function down from 1.3 ms to 1.1 ms.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>
2021-03-03 17:59:16 +00:00
Jonas Dreßler
7a5650d868 iconGrid: Bail out of getRowPadding early if we'll return 0
This gets our time spent in vfunc_allocate() down again by ~0.1 ms from
1.4 ms to 1.3 ms.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>
2021-03-03 17:59:15 +00:00
Jonas Dreßler
0fd394d4ca iconGrid: Don't update pages in vfunc_allocate()
vfunc_allocate() is a hot path, and we don't want to do expensive stuff
there, so avoid updating the pages, which seems unnecessary anyway.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>
2021-03-03 17:59:15 +00:00
Jonas Dreßler
0978b87e65 iconGrid: Get max child size using existing array of visible children
Using a preexisting array to iterate over is much faster than iterating
over the actors children using a "for ... of" loop, that's because the
latter calls into C functions to get the next actor all the time.

Also, stop using array deconstruction here, it turned out that this is
extremely expensive. When profiling this part of the code, it turned out
that only 9% of the time spent in _getChildrenMaxSize() is spent calling
the get_preferred_height/width() methods. When not using array
deconstruction, this time increased to 22%, still not great, but a lot
better.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>
2021-03-03 17:59:15 +00:00
Jonas Dreßler
8e93806453 iconGrid: Cache visible children of pages
We need to access the visible children of a page in inside
vfunc_allocate(), and since getting those children is quite slow (it
involves iterating over all the children of the actor) let's avoid that
and cache the array instead.

This reduces average time spent in vfunc_allocate() of the iconGrid from
1.6 ms down to 1.4 ms.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>
2021-03-03 17:59:15 +00:00
Jonas Dreßler
b3c46a33c0 iconGrid: Cache max size of children
We call this._getChildrenMaxSize() from the allocate() vfunc of
IconGridLayout. Since the function is quite expensive, it slows the
layout process down a lot, so instead of re-calculating it on every
relayout, cache the max size of children.

This makes the average time spent in vfunc_allocate() of the iconGrid go
down from 2.3 ms to 1.6 ms.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1713>
2021-03-03 17:59:15 +00:00
Carlos Garnacho
9e5b357b0b appDisplay: Adapt to available extra space showing icon grids
Depending on the available horizontal space, we may want to manipulate
the icon grid and scroll view spacing to result in an optimal layout
that has space left to preview prev/next pages.

The main change here is that, when adapting to the available size, the
space given to a page does not necessarily match the available space,
as we need to be able to show more than one page at a time.

With this decoupling of available and page sizes in place, we now know
how much space there is available in order to extend the padding between
pages, or the fade effect applied to the previewed pages.

Underneath, we rely a bit less on hardcoded CSS paddings, and a bit more
on the StScrollView::content-padding property.

All put together, gives us proper space management from ultra-wide
displays, to display ratios that are close to the optimal grid ratio.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1630>
2021-03-02 22:02:56 +00:00
Florian Müllner
252f2f5144 cleanup: Define GObject accessors in camelCase
gjs is smart enough to match a propertyName getter/setter to the
corresponding property-name GObject property, so use that and get
rid of the eslint camelcase rule exceptions.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1611>
2021-02-03 20:19:29 +01:00
Florian Müllner
0f1b566918 js: Use gjs-defined GObject accessors where possible
Nowadays gjs allows to omit get/set accessors for read-write properties,
and will define reasonable defaults in that case. In many cases we don't
need anything more than the default handling, let gjs handle those props.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1611>
2021-02-03 20:19:29 +01:00
Florian Müllner
3ff71ac40e iconGrid: Use correct default values in pspecs
The defaults are set in the code right now, but this is about to change.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1611>
2021-02-03 20:19:29 +01:00
Georges Basile Stavracas Neto
be279abe9e appDisplay: Make the app grid horizontal
Horizontal pagination is more natural than vertical, but for
historical reasons we ended up with a vertically paginated
app grid.

Make the app grid horizontal.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1554>
2021-01-04 15:37:45 +00:00
Georges Basile Stavracas Neto
b730875012 iconGrid/iconGrid: Wait for icon sizes before running spring animation
To run the spring animation, IconGrid uses the transformed position and size
of the icons. This works okay when IconGridLayout doesn't need to update the
icon sizes, but looks bad when IconGridLayout selects a different icon size.

Wait for the icon sizes to be recalculated, and the icons  beallocated, before
running the spring animation. If no icon size update is pending, run the spring
animation directly.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1518>
2020-12-02 22:43:04 +00:00
Georges Basile Stavracas Neto
b120b17d01 iconGrid/iconGridLayout: Simplify _findBestIconSize()
The 'bestSize' variable isn't necessary anymore, remove it in favor of
simply returning the 'size' or, if no suitable size found, IconSize.TINY.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1518>
2020-12-02 22:43:04 +00:00
Georges Basile Stavracas Neto
4863c498b2 iconGrid/iconGridLayout: Make sure to always update best size
When selecting the best icon size for the available area, we
iterate from the biggest icon size to the smallest one, and
stop when finding a size that fits the available area.

However, the 'bestSize' variable is only updated when the
available area is positive. This is problematic in super bad
cases like when none of the icon sizes actually fit the availabe
area, which was hit with a previous iteration of this branch.

Make sure to update the best size while iterating, so that the
smallest size is selected even in such bad cases.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1510>
2020-12-01 18:57:49 +00:00
Georges Basile Stavracas Neto
34e38a835c iconGrid/iconGridLayout: Floor children position
So that we don't end up with positions misaligned from the pixel grid.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1510>
2020-12-01 18:57:49 +00:00
Georges Basile Stavracas Neto
e667406984 iconGrid/iconGrid: Fill pages by default
Use the Clutter.ActorAlign.FILL alignment by default, which
expands the grid until max-row|column-spacing is hit. This
was the behavior we originally wanted for the icon grid, and
it's finally being realized.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1510>
2020-12-01 18:57:49 +00:00
Georges Basile Stavracas Neto
4ad32ab662 iconGrid/iconGrid: Hook page-padding with CSS
Add support for setting the page padding of the icon grid
through CSS. Unfortunately, each side needs to be specificied
manually, since it's not a regular padding property.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1510>
2020-12-01 18:57:49 +00:00
Georges Basile Stavracas Neto
5b6686095a iconGrid/iconGridLayout: Add support for page-padding
This is a new property to control the padding around each page,
as opposed to the padding around the entire container.

Following the original design of IconGridLayout [1], changing
the page-padding property doesn't trigger relayouts; the container
is responsible for queueing a relayout appropriately.

[1] 3555550d5e

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1510>
2020-12-01 18:57:49 +00:00
Georges Basile Stavracas Neto
4fcbf6c974 iconGrid: Allocate preferred sizes if bigger than child size
IconGridLayout uses the biggest minimum size to allocate its
children. Next commit will make app icons with long names show
not ellipsize on hover, and it is important that the icon itself
is able to follow that.

Use preferred size if it's bigger than the minimum size.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1477
2020-10-21 18:54:56 -03:00
Georges Basile Stavracas Neto
b3659221bd iconGrid: Trivial style cleanup
Turns out, we only needed a gentle push to get this whole
file fit in.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1477
2020-10-21 18:46:54 -03:00
Georges Basile Stavracas Neto
ffdff07eaf iconGrid: Add moveItem
This new public API moves items without removing and readding
them, which allows us to avoid some tricky behavior. Noticeably,
following the original design described at 3555550d5, the new
IconGridLayout.moveItem() method does not call `layout_changed`.
This is done by IconGrid itself, queueing a relayout.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1447
2020-10-05 12:06:47 +00:00
Georges Basile Stavracas Neto
f541562acc iconGrid: Properly remove pages
When the last item of an IconGridLayout page is removed,
the page itself is removed too. However, the indexes of
items of next pages are not updated, which mess up the
layout manager state.

Update the page index of the items at forward pages when
removing a page.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1406
2020-08-13 18:15:11 -03:00
Georges Basile Stavracas Neto
427b9ac75f iconGrid: Add drop target API
Add a new drop target API. The bulk of it is implemented by
IconGridLayout, since it's the layout manager that knows where
each icon is placed at.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1284
2020-07-20 16:13:19 +00:00
Georges Basile Stavracas Neto
8f547c9d5d iconGrid: Adjust animation delay
As per design feedback, adjust the animation delay to be shorter.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1332
2020-06-24 18:06:21 -03:00
Georges Basile Stavracas Neto
4c2c1297be appDisplay: Move child focus handling to IconGrid
The icon grid is always paginated, so the app grid code doesn't need
to behave differently in the FolderView and AppDisplay.

Move the keyboard handling to IconGrid itself, and remove the now dead
code from AppDisplay.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1271
2020-06-18 10:30:12 -03:00
Georges Basile Stavracas Neto
c5dbdad5fc iconGrid: Adapt grid layout according to available size
The new icon grid layout operates based on rows and columns, and
doesn't try to dynamically adapt it to fit to the container. In
this case, it is better to have a pre-defined set of well-known,
well-tested rows and columns, and switch between them based on
the aspect ratio of the screen.

Introduce a set of modes to the icon grid, and select the mode
that is closest to the aspect ratio.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1271
2020-06-18 10:30:12 -03:00
Georges Basile Stavracas Neto
4e05bcd3b6 iconGrid: Use IconGridLayout
Replace the current grid code with IconGridLayout.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1271
2020-06-18 10:30:12 -03:00
Georges Basile Stavracas Neto
3555550d5e iconGrid: Introduce IconGridLayout
IconGridLayout is a new layout manager that aims to replace the
current paginated layout algorithm implemented by the icon grid.

There are a few outstanding aspects of this new layout manager
that are worth highlighting. IconGridLayout implements all the
mechanisms necessary for a paginated icon grid, but doesn't
implement any policies around it. The reason behind this decision
is that this layout manager will be used by other places (e.g.
the login dialog) that demand different policies to how the
grid should look like.

Another important aspect of this grid is that it does not queue
any relayouts when changing its properties. If a relayout is
required, the actor should manually queue it. This is necessary
to avoid layout loops.

Add the IconGridLayout class. Next commits will do the surgery
to IconGrid and any related code to use this new layout manager.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1271
2020-06-18 10:30:12 -03:00
Georges Basile Stavracas Neto
be02f76aa7 iconGrid: Trivial comment cleanup
There's no PaginatedIconGrid anymore

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1301
2020-06-09 16:14:30 -03:00
Georges Basile Stavracas Neto
8154728d09 environment: Add Math.clamp
The good old clamp function, now part of the Math family.
Clamp is happy after so many years of loneliness.

This is a strict implementation of the draft ECMAScript
proposal.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1295
2020-06-03 12:55:53 -03:00
Florian Müllner
dc27db0897 iconGrid: Remove fillParent support
This was only used by the frequent view to display as many children
as fit the available space. Now that the view is gone, there's no
need to keep the support ...

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1286
2020-05-28 00:31:49 +02:00
Georges Basile Stavracas Neto
f09fbb19cf iconGrid: Merge PaginatedIconGrid and IconGrid
Now that the only user of the IconGrid is AppDisplay, and
it only uses the paginated icon grid, there's no point in
having the two classes split anymore.

In addition to that, future commits will introduce a layout
manager that will extend current icon grid features, and
merging PaginatedIconGrid and IconGrid in the same class will
vastly simplify this transition.

Merge PaginatedIconGrid into IconGrid, and adapt AppDisplay
to this change.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1267
2020-05-27 19:23:56 -03:00
Jonas Dreßler
9b99b67fea Remove ClutterAllocationFlags
Those flags were removed from Clutter since they're pretty much unused,
so remove them here, too.

See https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1245

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1245
2020-05-20 15:12:03 +02:00
Georges Basile Stavracas Neto
693dd79d28 iconGrid: Remove dead code
Remove unused methods from IconGrid.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1265
2020-05-19 16:40:49 -03:00
Georges Basile Stavracas Neto
402fd8ec29 iconGrid: Downscale icon size when comparing to defaults
The return value of st_theme_node_lookup_length() is scaled according
to the scale factor. IconGrid.ICON_SIZE is not. However, when BaseIcon
tries to fetch the CSS value for "icon-size" (which returns a scaled
value), it uses it as-is, mixing the two coordinate systems.

Use a single coordinate system (unscaled sizes) in IconGrid.BaseIcon.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1175
2020-04-03 16:04:40 -03:00
Daniel van Vugt
e781e1fdba iconGrid: Create icon clones in a separate loop
For reasons not yet fully understood, `Main.uiGroup.add_actor` takes around
10 milliseconds to complete.

Because of this, each `actor.opacity = 0` has a good chance of falling
on a different frame. And when it does, `_opacityChangedId` also lands
on multiple different frames each incurring a separate relayout cycle.
It is this excessive number of relayouts that causes stuttering in the
icon grid animation (#2065). But it is the slowness of `uiGroup.add_actor`
that causes the number to be excessive when it should be one.

By creating the clones and adding them to `uiGroup` early, we then enable
the existing loop starting the animation to complete within a single frame.
And by completing within a single frame all the opacity changes land within
the same frame interval, thus incurring only a single relayout instead of
many.

This issue went unnoticed until 004a5e1042 (!704), after which the slow
emissions of `notify::opacity` became a more visible performance problem.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/issues/2065

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/1002
2020-02-19 15:39:21 +00:00
Daniel van Vugt
b5651e38c7 iconGrid: Avoid animating the same icon twice
If the icon proper has opacity of zero then that's probably because a
clone of it is animating. So avoid animating the source actor too.

And if there's any other reason for the opacity being zero, still don't
animate it because we can't see it :)

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/issues/2167
2020-02-07 11:31:20 +00:00
Georges Basile Stavracas Neto
1dad5f3ffa iconGrid: Remove API to open space between icons
Since we moved to showing folders as dialogs now, there's no need
to keep this API. Remove it.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/896
2020-01-21 10:49:56 -03:00
Georges Basile Stavracas Neto
0e3a2654d4 iconGrid: Animate icon positions
As per design guidance, animate the icons when the grid changes.
Each icon takes 250ms to transition, and starts moving 25ms after
the previous one.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/882
2020-01-20 16:40:42 +01:00
Daniel van Vugt
76961927d5 iconGrid.js: Animate icon spring using translation
Animating the icon spring using the `translation-x/y` properties instead
of the `x/y` properties avoids relayouts. There are still other non-icon
actors moving, but it's a big improvement.

Before: 595 relayouts per spring
After: 94 relayouts per spring

Reducing relayouts reduces reallocation, which reduces CPU-intensive
JavaScript execution.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/926
2020-01-13 16:23:37 +08:00
Florian Müllner
f5f9bd2e5e iconGrid: Fix icon alignment
We don't want the icon to fill extra space, so set the alignment
accordingly. Otherwise we get an unexpected result when adding
a background just to the icon part (as far as I can tell: just
system-action-icon).

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/909
2019-12-20 22:58:26 +01:00
Florian Müllner
61210fdae1 cleanup: Use JSDoc for documentation comments
It's a better fit than gtk-doc, and eslint can validate that they
are complete and use correct syntax.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/805
2019-11-11 19:25:14 +00:00