Fixes for taskbar app
This commit is contained in:
@@ -88,6 +88,9 @@ internal static partial class X11
|
|||||||
[LibraryImport(LibX11, StringMarshalling = StringMarshalling.Utf8)]
|
[LibraryImport(LibX11, StringMarshalling = StringMarshalling.Utf8)]
|
||||||
public static partial int XStoreName(IntPtr display, IntPtr window, string windowName);
|
public static partial int XStoreName(IntPtr display, IntPtr window, string windowName);
|
||||||
|
|
||||||
|
[LibraryImport(LibX11)]
|
||||||
|
public static partial int XSetClassHint(IntPtr display, IntPtr window, ref XClassHint classHint);
|
||||||
|
|
||||||
[LibraryImport(LibX11)]
|
[LibraryImport(LibX11)]
|
||||||
public static partial int XRaiseWindow(IntPtr display, IntPtr window);
|
public static partial int XRaiseWindow(IntPtr display, IntPtr window);
|
||||||
|
|
||||||
|
|||||||
13
Interop/XClassHint.cs
Normal file
13
Interop/XClassHint.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// Licensed to the .NET Foundation under one or more agreements.
|
||||||
|
// The .NET Foundation licenses this file to you under the MIT license.
|
||||||
|
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Microsoft.Maui.Platform.Linux.Interop;
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct XClassHint
|
||||||
|
{
|
||||||
|
public IntPtr res_name;
|
||||||
|
public IntPtr res_class;
|
||||||
|
}
|
||||||
@@ -265,6 +265,18 @@ public class LinuxApplication : IDisposable
|
|||||||
Console.WriteLine("[LinuxApplication] GTK pre-initialized for WebView support");
|
Console.WriteLine("[LinuxApplication] GTK pre-initialized for WebView support");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set application name for desktop integration (taskbar, etc.)
|
||||||
|
// Try to get the name from environment or use executable name
|
||||||
|
string? appName = Environment.GetEnvironmentVariable("APPIMAGE_NAME");
|
||||||
|
if (string.IsNullOrEmpty(appName))
|
||||||
|
{
|
||||||
|
appName = Path.GetFileNameWithoutExtension(Environment.ProcessPath ?? "MauiApp");
|
||||||
|
}
|
||||||
|
string prgName = appName.Replace(" ", "");
|
||||||
|
GtkNative.g_set_prgname(prgName);
|
||||||
|
GtkNative.g_set_application_name(appName);
|
||||||
|
Console.WriteLine($"[LinuxApplication] Set application name: {appName} (prgname: {prgName})");
|
||||||
|
|
||||||
// Initialize dispatcher
|
// Initialize dispatcher
|
||||||
LinuxDispatcher.Initialize();
|
LinuxDispatcher.Initialize();
|
||||||
DispatcherProvider.SetCurrent(LinuxDispatcherProvider.Instance);
|
DispatcherProvider.SetCurrent(LinuxDispatcherProvider.Instance);
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ internal static class GtkNative
|
|||||||
[DllImport("libgtk-3.so.0")]
|
[DllImport("libgtk-3.so.0")]
|
||||||
public static extern void gtk_window_set_title(IntPtr window, string title);
|
public static extern void gtk_window_set_title(IntPtr window, string title);
|
||||||
|
|
||||||
|
[DllImport("libglib-2.0.so.0")]
|
||||||
|
public static extern void g_set_prgname(string name);
|
||||||
|
|
||||||
|
[DllImport("libglib-2.0.so.0")]
|
||||||
|
public static extern void g_set_application_name(string name);
|
||||||
|
|
||||||
[DllImport("libgtk-3.so.0")]
|
[DllImport("libgtk-3.so.0")]
|
||||||
public static extern void gtk_window_set_default_size(IntPtr window, int width, int height);
|
public static extern void gtk_window_set_default_size(IntPtr window, int width, int height);
|
||||||
|
|
||||||
|
|||||||
@@ -150,6 +150,9 @@ public class X11Window : IDisposable
|
|||||||
// Set window title
|
// Set window title
|
||||||
X11.XStoreName(_display, _window, title);
|
X11.XStoreName(_display, _window, title);
|
||||||
|
|
||||||
|
// Set WM_CLASS for desktop integration (taskbar icon matching)
|
||||||
|
SetWMClass(title.Replace(" ", ""), title.Replace(" ", ""));
|
||||||
|
|
||||||
// Select input events
|
// Select input events
|
||||||
X11.XSelectInput(_display, _window,
|
X11.XSelectInput(_display, _window,
|
||||||
XEventMask.KeyPressMask |
|
XEventMask.KeyPressMask |
|
||||||
@@ -196,6 +199,37 @@ public class X11Window : IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the WM_CLASS property for desktop integration.
|
||||||
|
/// This allows the desktop to match the window to its .desktop file.
|
||||||
|
/// </summary>
|
||||||
|
public void SetWMClass(string resName, string resClass)
|
||||||
|
{
|
||||||
|
IntPtr namePtr = IntPtr.Zero;
|
||||||
|
IntPtr classPtr = IntPtr.Zero;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
namePtr = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(resName);
|
||||||
|
classPtr = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(resClass);
|
||||||
|
|
||||||
|
var classHint = new XClassHint
|
||||||
|
{
|
||||||
|
res_name = namePtr,
|
||||||
|
res_class = classPtr
|
||||||
|
};
|
||||||
|
|
||||||
|
X11.XSetClassHint(_display, _window, ref classHint);
|
||||||
|
Console.WriteLine($"[X11Window] Set WM_CLASS: {resName}, {resClass}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (namePtr != IntPtr.Zero)
|
||||||
|
System.Runtime.InteropServices.Marshal.FreeHGlobal(namePtr);
|
||||||
|
if (classPtr != IntPtr.Zero)
|
||||||
|
System.Runtime.InteropServices.Marshal.FreeHGlobal(classPtr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the window icon from a file. Supports both raster images and SVG.
|
/// Sets the window icon from a file. Supports both raster images and SVG.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user