Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AppSystem/App.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Dock.App : Object {
public signal void removed ();

public bool pinned { get; construct set; }
public GLib.DesktopAppInfo app_info { get; construct; }
public Dock.AppInfo app_info { get; construct; }

public bool count_visible { get; private set; default = false; }
public int64 current_count { get; private set; default = 0; }
Expand Down Expand Up @@ -55,7 +55,7 @@ public class Dock.App : Object {

private SimpleAction pinned_action;

public App (GLib.DesktopAppInfo app_info, bool pinned) {
public App (Dock.AppInfo app_info, bool pinned) {
Object (app_info: app_info, pinned: pinned);
}

Expand Down
107 changes: 107 additions & 0 deletions src/AppSystem/AppInfo.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* SPDX-License-Identifier: GPL-3.0
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
*/

public class Dock.AppInfo : GLib.Object {
private const string[] NULL_ACTIONS = {};
private GLib.Icon fallback_icon = new GLib.ThemedIcon ("application-default-icon");

public GLib.DesktopAppInfo? desktop_app_info { get; construct; }

private string _fake_id = "Unknown";
public string? fake_id {
private get {
return _fake_id;
}
set {
_fake_id = value ?? "Unknown";
}
}

private string _fake_name = "Unknown";
public string? fake_name {
private get {
return _fake_name;
}
set {
_fake_name = value ?? "Unknown";
}
}

public AppInfo (GLib.DesktopAppInfo? desktop_app_info) {
Object (desktop_app_info: desktop_app_info);
}

public unowned string get_id () {
if (desktop_app_info == null) {
return fake_id;
}

return desktop_app_info.get_id ();
}

public unowned string get_display_name () {
if (desktop_app_info == null) {
return fake_name;
}

return desktop_app_info.get_display_name ();
}

public unowned GLib.Icon get_icon () {
if (desktop_app_info == null) {
return fallback_icon;
}

return desktop_app_info.get_icon () ?? fallback_icon;
}

public bool get_boolean (string key) {
if (desktop_app_info == null) {
return false;
}

return desktop_app_info.get_boolean (key);
}

public string get_string (string key) {
if (desktop_app_info == null) {
return "";
}

return desktop_app_info.get_string (key);
}

public unowned string[] list_actions () {
if (desktop_app_info == null) {
return NULL_ACTIONS;
}

return desktop_app_info.list_actions ();
}

public string get_action_name (string action_name) {
if (desktop_app_info == null) {
return "Something went wrong if you see this";
}

return desktop_app_info.get_action_name (action_name);
}

public void launch_action (string action_name, GLib.AppLaunchContext launch_context) {
if (desktop_app_info == null) {
return;
}

desktop_app_info.launch_action (action_name, launch_context);
}

public bool launch (GLib.List<GLib.File>? files, GLib.AppLaunchContext? context) throws GLib.Error {
if (desktop_app_info == null) {
return false;
}

return desktop_app_info.launch (files, context);
}
}
20 changes: 11 additions & 9 deletions src/AppSystem/AppSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ public class Dock.AppSystem : Object, UnityClient {

public async void load () {
foreach (string app_id in settings.get_strv ("launchers")) {
var app_info = new GLib.DesktopAppInfo (app_id);
add_app (app_info, true);
add_app (new Dock.AppInfo (new GLib.DesktopAppInfo (app_id)), true);
}

yield sync_windows ();
WindowSystem.get_default ().notify["windows"].connect (sync_windows);
}

private App add_app (DesktopAppInfo app_info, bool pinned) {
private App add_app (Dock.AppInfo app_info, bool pinned) {
var app = new App (app_info, pinned);
id_to_app[app_info.get_id ()] = app;
app.removed.connect ((_app) => id_to_app.remove (_app.app_info.get_id ()));
Expand All @@ -54,9 +53,12 @@ public class Dock.AppSystem : Object, UnityClient {
foreach (var window in windows) {
App? app = id_to_app[window.app_id];
if (app == null) {
var app_info = new GLib.DesktopAppInfo (window.app_id);
if (app_info == null) {
continue;
var desktop_app_info = new GLib.DesktopAppInfo (window.app_id);
var app_info = new Dock.AppInfo (desktop_app_info);

if (desktop_app_info == null) {
app_info.fake_name = window.title != null ? window.title : window.app_id;
app_info.fake_id = window.app_id;
}

app = add_app (app_info, false);
Expand Down Expand Up @@ -85,14 +87,14 @@ public class Dock.AppSystem : Object, UnityClient {
return;
}

var app_info = new DesktopAppInfo (app_id);
var desktop_app_info = new DesktopAppInfo (app_id);

if (app_info == null) {
if (desktop_app_info == null) {
warning ("App not found: %s", app_id);
return;
}

add_app (app_info, true);
add_app (new Dock.AppInfo (desktop_app_info), true);
}

public void remove_app_by_id (string app_id) {
Expand Down
4 changes: 3 additions & 1 deletion src/AppSystem/Launcher.vala
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ public class Dock.Launcher : BaseItem {
}
break;
case Gdk.BUTTON_SECONDARY:
popover.popup ();
if (app.app_info.desktop_app_info != null) {
popover.popup ();
}
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ItemManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
}

var file = (File) drop_target_file.get_value ().get_object ();
var app_info = new DesktopAppInfo.from_filename (file.get_path ());
var app_info = new GLib.DesktopAppInfo.from_filename (file.get_path ());

if (app_info == null) {
return;
Expand Down
6 changes: 5 additions & 1 deletion src/WindowSystem/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

public class Dock.Window : GLib.Object {
public uint64 uid { get; construct set; }

public string app_id { get; private set; default = ""; }
public string? title { get; private set; default = null; }
public bool has_focus { get; private set; default = false; }
public int workspace_index { get; private set; default = 0; }
public int64 time_appeared_on_workspace { get; private set; default = 0; }
Expand All @@ -23,6 +23,10 @@ public class Dock.Window : GLib.Object {
app_id = properties["app-id"].get_string ();
}

if ("title" in properties) {
title = properties["title"].get_string ();
}

if ("has-focus" in properties) {
has_focus = (bool) properties["has-focus"];
}
Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ sources = [
'ItemManager.vala',
'MainWindow.vala',
'AppSystem' / 'App.vala',
'AppSystem' / 'AppInfo.vala',
'AppSystem' / 'AppSystem.vala',
'AppSystem' / 'Launcher.vala',
'AppSystem' / 'PoofPopover.vala',
Expand Down