Commit Graph

160 Commits

Author SHA1 Message Date
Florian Müllner
86b5a43008 shell/app: Add new get_icon() method
Now that we can always associate a GIcon with the app, add a method
to access it. While create_icon_texture() is still likely to be more
convenient in most cases, exposing the icon can still be useful, for
example to add it to a different kind of actor or to compare it with
other GIcons.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1342
2020-07-01 12:42:57 +02:00
Florian Müllner
d7cb2eeebc st/texture-cache: Return a GIcon from bind_cairo_surface_property()
We still load the surface into an StImageContent, but instead of
adding the content to an actor we hand out, return the content
itself (as GIcon).

That means we lose the ability to specify an icon size, but as we
get the pixel data from a fixed-size surface anyway, that shouldn't
matter much in practice.

Not to mention that the function is only used for fallback X11 icons,
which are already shit more often than not.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1342
2020-07-01 12:42:57 +02:00
Jonas Dreßler
b88ed3f251 Use pid_t for meta_window_get_pid()
The return value of meta_window_get_pid() changed again and it now
returns pid_t, which usually just resolves to int on most platforms. We
should still use pid_t now though, so do that.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1188
2020-05-21 23:11:21 +00:00
Bastien Nocera
34da48453e shell-app: Add PrefersNonDefaultGPU support to shell_app_launch()
Read the "PrefersNonDefaultGPU" key in desktop files to figure out
whether the application prefers running on the discrete GPU, or the
default GPU, and apply that.

Update the "Launch..." contextual menu to allow launching on
the default GPU if the application "prefers [the] non default GPU".

See:
https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/1804
2020-05-04 16:22:03 +02:00
Bastien Nocera
13dcd78be1 shell-app: Downgrade not finding a discrete GPU to debug
As we'll want to call this unconditionally soon.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1226
2020-05-04 16:22:03 +02:00
Bastien Nocera
9d7832ea44 shell/global: Make switcheroo-control available from JS
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1226
2020-05-04 16:22:03 +02:00
Jonas Dreßler
d4db5a59c1 shell-app: Ignore invalid window PIDs
When building the list of window PIDs, it's possible Mutter doesn't know
about the PID the client has and meta_window_get_pid() will return 0. We
should handle this case by not adding the PID to the list of PIDs
instead of adding an invalid one to it.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1184
2020-04-06 21:53:37 +00:00
Jonas Dreßler
85846d88f0 shell-app: Use container widget for fallback X11 app icons
Just like StIcon does, we should use a container widget for the fallback
app icon that we get using the cairo surface property. It's needed
because the widget returned by shell_app_create_icon_texture() can be
resized freely, while we want the aspect ratio of the actual texture to
remain the same.

Fixes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2578
2020-04-06 08:28:26 +00:00
Florian Müllner
bf367daaba build: Fix some harmless compiler warnings
Some (newer?) GCC versions complain when a g_auto variable isn't
initialized when declared, even when the initialization is guaranteed
to happen before the variable is used or goes out of scope.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/2298
2020-03-08 00:34:36 +00:00
Florian Müllner
d9b3d6745c app: Use better icon for wayland window-backed apps
For window-backed apps (read: windows we can't match to a .desktop
file), we use the window's icon property as icon. However there is
no such property on wayland (at least in the protocols we support),
so we end up with a blank actor in that case.

Do better than that, and pick a generic fallback icon instead.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/1779
2020-01-23 18:25:28 +00:00
Bastien Nocera
0223d38602 shell-app: Add discrete GPU support for NVidia drivers
Use data from switcheroo-control to know which environment variables
to use to launch an application on the discrete GPU. switcheroo-control
version 2.0 or newer should be installed on Linux platforms.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/issues/1810
2019-12-13 00:44:28 +01:00
Robert Mader
135d178d08 cleanup: Use g_clear_signal_handler() where possible
`g_clear_signal_handler()` is usually cleaner and saver than
`g_signal_handler_disconnect()`. We use it new code, lets also
adopt the existing one.

See also https://gitlab.gnome.org/GNOME/mutter/merge_requests/868
and https://gitlab.gnome.org/GNOME/mutter/merge_requests/940

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/842
2019-11-21 22:37:37 +00:00
Jonas Ådahl
88bcaafe86 Stop referring to ClutterTexture
ClutterTexture is removed from mutter's clutter fork, so lets stop
referring to it. This also happens to fix an incorrect type cast.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/822
2019-11-12 22:05:13 +01:00
Jonas Dreßler
00e95de114 shell-app: Never allow opening new windows while an app is starting
We allow opening new windows as a fallback in case the app doesn't give
us explicit information about it, but we don't want to allow opening new
windows if we're unable to ask for this information (we can only use the
APIs to get this information while the app is RUNNING).

So always return FALSE in case the app is STARTING, always return TRUE
in case the app is STOPPED (starting an app always opens a new window)
and go through the usual checks in case the app is RUNNING (and
eventually fall back to FALSE).

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/121
2019-09-18 17:14:16 +00:00
Florian Müllner
1e6cb43815 shell-app: Consider desktop actions in can_open_new_window()
We currently only consider a remote "app.new-window" action when running,
but not a fixed "new-window" action in the .desktop file. The latter is
clearly useful as well, in particular as open_new_window() already does,
so add it.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/665
2019-08-06 15:04:24 +02:00
Niels De Graef
28ab1f4af4 Ensure G_PARAM_STATIC_STRINGS for all properties
In `st`, we can do this by using `ST_PARAM_*`. In the other code files,
just use `G_PARAM_STATIC_STRINGS` directly.

This is just a minor convenience to prevent a few unnecessary string
copies.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/646
2019-07-30 13:58:44 +00:00
Laurent Bigonville
58c4212cfa shell-app: Fix spelling error
https://gitlab.gnome.org/GNOME/gnome-shell/issues/1205
2019-06-15 12:08:40 +02:00
Carlos Garnacho
5a9d094f3e shell: Use MetaDisplay input focus API
Replaces use of (now removed) MetaX11Display focus API (which happened to
work for wayland too).

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/378
2019-05-24 12:24:06 +02:00
Simon McVittie
0f531d8c44 ShellApp: Use g_signal_connect_object for window signals
A window being unmanaged can cause the ShellApp to be removed from
the ShellAppSystem, which if we are unlucky is the app's last
reference, causing it to be disposed and freed. It would be bad if this
happened before we finished handling the signal.

Use g_signal_connect_object to ensure that a reference is held to
the ShellApp for the duration of the signal handler, delaying its
last-unref.

In particular, when a signal handler calls _shell_app_remove_window(),
there is a brief period for which ShellApp breaks the intended
invariant (see !497) that app->running_state is non-NULL if and only if
app->running_state->windows is also non-NULL (non-empty). Freeing the
ShellApp at this point would cause a crash. This seems likely to be the
root cause of <https://gitlab.gnome.org/GNOME/gnome-shell/issues/750>,
<https://gitlab.gnome.org/GNOME/gnome-shell/issues/822> and
<https://bugs.debian.org/926212>.

Signed-off-by: Simon McVittie <smcv@debian.org>
2019-04-23 12:51:56 +00:00
Florian Müllner
1767cd0f6c app: Consider "quit" action for quit
Just like we take a remote "new-window" action into account for
opening new windows, we should call an explicit "quit" action
before falling back to closing all the app's windows on quit.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/624
2019-03-28 00:02:20 +00:00
Florian Müllner
4f65283f31 app: Set styleclass on fallback app icons
For window backed apps, create_icon_texture() doesn't return an StIcon
but a generic widget. Set an appropriate style class to make it easier
to apply a specific style only to fallback icons.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/1027
2019-03-08 16:20:21 +01:00
Florian Müllner
6f794738e8 texture-cache: Load bound surfaces into StWidgets
Using widgets instead of plain actors will allow us to set the size
from CSS.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/1027
2019-03-08 16:20:21 +01:00
Marco Trevisan (Treviño)
19c60ff5c5 st-texture-cache: use StImageContent for cairo bound surface
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/5
2019-03-01 17:12:53 +00:00
Florian Müllner
753618a19f app: Remove :menu property
It is now unused.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/624
2019-02-06 18:29:15 +01:00
Florian Müllner
e355756758 app: Don't rely on app menu to check for GtkApplications
As the app menu is being phased out, it is no longer a good indicator
for GtkApplications. Instead, base the check directly on the appropriate
D-Bus properties.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/624
2019-02-06 18:29:15 +01:00
Florian Müllner
446183adee app: Remove unused code
This was overlooked back in the day when application search moved into GIO.
2019-02-05 01:54:17 +01:00
Georges Basile Stavracas Neto
69b1fb699f
app: Replace ClutterTexture by ClutterActor
It apparently uses no ClutterTexture specifics, and instead
only tries to match what StTextureCache used to return.

Since StTextureCache now returns ClutterActor, also use a
ClutterActor on ShellApp.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/373
2019-01-29 17:11:13 -02:00
Carlos Garnacho
10b3671a99 shell: Use MetaStartupNotification
This is "API compatible" with ShellStartupNotification, so only
C changes are necessary.
2018-11-23 13:58:35 +01:00
Florian Müllner
87a645aa2b app: Close all closable windows from quit()
There's no relation between a window being hidden from overview/taskbars
and a window not being closable - currently we effectively disable the
fallback quit action for any application with open transients, which
simply doesn't make sense.

Instead, only exclude windows for which the close action has been
explicitly disabled.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/217
2018-09-13 10:54:39 +00:00
Daniel Drake
4b522a02c3 shell-app: remove child_setup from app launching
When the amount of free memory on the system is somewhat low, gnome-shell
will sometimes fail to launch apps, reporting the error:
  fork(): Cannot allocate memory

fork() is failing here because while cloning the process virtual address
space, Linux worries that the thread being forked may end up COWing the
entire address space of the parent process (gnome-shell, which is
memory-hungry), and there is not enough free memory to permit that to
happen. This check is somewhat irrelevant because we are only forking
to immediately exec(), which will discard the whole virtual address
space anyway.

This issue can be avoided by using a new optimized gspawn codepath in
the latest glib development version, which uses posix_spawn() internally.

For the optimized codepath to be used, we must not pass a child_setup
function, so the the file descriptor management is reimplemented here
using new glib API to pass fds to the child process. The old API will
continue to be used on older glib versions.

We must also change the spawn flags for this code path to be hit.
I checked that gnome-shell's open file descriptors are all CLOEXEC
so using G_SPAWN_LEAVE_DESCRIPTORS_OPEN should be safe.

This will result in more resilient app launching when memory is low,
since the optimized spawn path avoids cloning the virtual address
space of the parent process (gnome-shell) and avoids the irrelevant
memory overcommit check.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/132
2018-07-30 23:11:41 +00:00
Florian Müllner
3efd296fc3 app: Consider "new-window" action for opening new windows
While can_open_new_window() uses some elaborate heuristics to predict
whether an application can open multiple windows, open_new_window()
will always simply relaunch the application. This is often the best
we can do, but when an application provides a "new-window" action in
its .desktop file or on the bus, it is much more likely to work as
expected than blindly activating the app and hoping for a particular
behavior.

https://bugzilla.gnome.org/show_bug.cgi?id=756844
2018-07-30 19:21:40 +00:00
Jonas Ådahl
47ea10b7c9 Remove usage of MetaScreen
Remove any usage of MetaScreen, as it has been removed from libmutter
in the API version 3. The corresponding functionality has been moved
into three different places: MetaDisplay, MetaX11Display (for X11
specific functionality) and MetaWorkspaceManager.

https://bugzilla.gnome.org/show_bug.cgi?id=759538
2018-07-06 19:56:19 +02:00
Mario Sanchez Prada
b5f5a594ba shell-app: Don't transition to STOPPED while still in the STARTING state
Similar to what it's done in _shell_app_add_window(), rely on calling
shell_app_sync_running_state() when removing windows too, to avoid
transitioning to STOPPED while it's still in the STARTING state.

This makes the logic compliant with the startup notification spec and
prevents stopping an application too early if it has a splash screen
that has been closed before the application's main window is shown.

https://bugzilla.gnome.org/show_bug.cgi?id=787905
2017-09-29 18:10:23 +01:00
Florian Müllner
053b8da89c app: Work around pkexec restriction when launching
Unless automatic child reaping is disabled in GSpawnFlags, glib's
g_spawn_* functions will reparent the spawned process to init by
double-forking. Unfortunately pkexec bails out in this case[0],
which means that it no longer works in .desktop files since the
PID tracking removal in commit 01c6392c13.
Fix this by going back to manual child reaping.

[0] https://cgit.freedesktop.org/polkit/tree/src/programs/pkexec.c#n728

https://bugzilla.gnome.org/show_bug.cgi?id=763531
2017-09-12 17:32:51 +02:00
Bastien Nocera
39a840e2c3 shell-app: Add "discrete_gpu" option when launching apps
And adapt existing callers to the new API. This will allow us to
implement a way to launch applications on the discrete GPU for systems
where an "Optimus" system exists.

https://bugzilla.gnome.org/show_bug.cgi?id=773117
2016-10-21 19:26:49 +02:00
Florian Müllner
2f0039e7dd app: Add a construct-only app-info property
This will allow us to create a ShellApp from JS code, for instance
for .desktop files that aren't known to the AppSystem.

https://bugzilla.gnome.org/show_bug.cgi?id=762206
2016-07-13 01:28:13 +02:00
Florian Müllner
84da49c715 app: Consider minimized windows for app comparisons
We used to take window visibility into account when comparing apps
until commit 1dfc38d078, following changes in the window switcher
due to auto-minimization. However auto-minimization was abolished
and the window switcher changes reverted, so it makes sense again
to sort apps without non-minimized windows last again.

https://bugzilla.gnome.org/show_bug.cgi?id=766238
2016-05-10 21:36:33 +02:00
Owen W. Taylor
db297e7fdb Don't crash on accesses to stale window-backed apps
The JS code could still be holding on to a reference to a window-backed app
after all windows have vanished. (For example, the dash queues an idle to
refetch apps and display them.) Avoid dying with an error message if we
attempt to activate or otherwise manipulate such a window.

https://bugzilla.gnome.org/show_bug.cgi?id=674799
2015-10-11 15:31:39 -04:00
Florian Müllner
3e10574736 shell: Add default case to switch statements
... to shut up a compiler warning.
2015-09-23 21:32:50 +02:00
Florian Müllner
825146f1e3 shell: Fix signed-unsigned comparisons 2015-09-23 21:32:50 +02:00
Jasper St. Pierre
7424ee755a shell-app: Stay consistent about application states
When the last interesting window of an app-backed window is removed,
we'll transition it back to STOPPED, but we transition the state and
send out the signal before we clear the running state.

This means that any listeners to the state-changed signal might
encounter a window-backed app that has a running state, but no
windows. If they call, e.g. shell_app_get_name, while in this state,
they'll encounter an assertion fail.
2015-07-16 17:09:39 -07:00
Jasper St. Pierre
ff664fd1d8 shell-app: Track the starting state correctly
Apps that are starting might have uninteresting windows like splash
screens pop up and then go away (like LibreOffice), even when
startup-notification hasn't completed yet. In those cases, we don't
want to transition the app back to stopped -- it should remain in
the running state.
2015-07-16 15:21:57 -07:00
Cosimo Cecchi
f812e9be7d ShellApp: use st_icon_set_fallback_icon_name() to specify app fallback
We can now safely pass a NULL GIcon to st_icon_set_gicon(), and specify
a more generic fallback using the new API we just introduced.

https://bugzilla.gnome.org/show_bug.cgi?id=746219
2015-03-14 17:31:07 -07:00
Jasper St. Pierre
71ae7e69c5 shell-app: Remove leftover struct 2015-02-20 17:40:45 -08:00
Carlos Soriano
ef3285d5e7 shell-app: Remove shell_app_get_faded_icon
In previous commit we removed the only use of shell_app_get_faded_icon
so we can remove the function on shell-app as well.

https://bugzilla.gnome.org/show_bug.cgi?id=744680
2015-02-20 15:14:44 +01:00
Florian Müllner
21056a967f Revert "shell-app: Fix typo"
This reverts commit ead4c2b863.
2015-01-30 18:01:57 +01:00
Florian Müllner
ead4c2b863 shell-app: Fix typo
Commit 086fcd4a32 broke the build, use the correct variable to fix.

https://bugzilla.gnome.org/show_bug.cgi?id=743729
2015-01-30 17:59:30 +01:00
Jasper St. Pierre
086fcd4a32 shell-app: Only raise windows on the same workspace when activating them
For some reason, we never did this, even though this is what the comment
says we should be doing.
2015-01-30 11:36:45 -05:00
Rui Matos
af889168f0 StTextureCache: adapt to MetaWindow changing icon prop type
Mutter change is
https://git.gnome.org/browse/mutter/commit/?id=af7f51b992b20da543312fa9fdf1dcef39704b37

https://bugzilla.gnome.org/show_bug.cgi?id=742824
2015-01-13 15:58:45 +01:00
Sebastian Keller
01c6392c13 window-tracker: remove now unused launched_pid_to_app
https://bugzilla.gnome.org/show_bug.cgi?id=736527
2014-12-28 16:40:20 -08:00