[英]How do i get information about the window that has focus on Linux using Mono C#
我已經使用 Windows 用戶組件 (user32.dll) 開發了一個 C# .NET WindowsForms 應用程序,每次用戶更改焦點時,該組件都會保存活動窗口(具有焦點的窗口)的標題。
現在我打算在 Linux 上使用 Mono C# 做同樣的事情。 是否有可能?
如果是,我在尋找什么?
我決定看一看gnome-screenshot
的來源,它具有這樣的功能(僅截取活動窗口的屏幕截圖):
static GdkWindow *
screenshot_find_active_window (void)
{
GdkWindow *window;
GdkScreen *default_screen;
default_screen = gdk_screen_get_default ();
window = gdk_screen_get_active_window (default_screen);
return window;
}
當上面沒有返回任何內容時,它有一些邏輯可以回退到“鼠標指針下的窗口”:
GdkWindow *
do_find_current_window (void)
{
GdkWindow *current_window;
GdkDeviceManager *manager;
GdkDevice *device;
current_window = screenshot_find_active_window ();
manager = gdk_display_get_device_manager (gdk_display_get_default ());
device = gdk_device_manager_get_client_pointer (manager);
/* If there's no active window, we fall back to returning the
* window that the cursor is in.
*/
if (!current_window)
current_window = gdk_device_get_window_at_position (device, NULL, NULL);
if (current_window)
{
if (screenshot_window_is_desktop (current_window))
/* if the current window is the desktop (e.g. nautilus), we
* return NULL, as getting the whole screen makes more sense.
*/
return NULL;
/* Once we have a window, we take the toplevel ancestor. */
current_window = gdk_window_get_toplevel (current_window);
}
return current_window;
}
據我所知,以上所有內容都依賴於 libgdk-pixbuf。 如果這不是一個選項,您可以隨時查看 Gdk 源代碼中這些函數的實現。
我正在嘗試在Linux中使用python來使鼠標單擊/突出顯示窗口名稱/標題。 但是我一無所知。
或任何其他語言都可以獲取窗口名稱? 有可能嗎?有辦法嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.