简体   繁体   English

我如何使用 Mono C# 获取有关关注 Linux 的窗口的信息

[英]How do i get information about the window that has focus on Linux using Mono C#

I already developed an C# .NET WindowsForms application using the Windows user component (user32.dll) that saves the title of the active window (the window that has focus) every time the user changes focus.我已经使用 Windows 用户组件 (user32.dll) 开发了一个 C# .NET WindowsForms 应用程序,每次用户更改焦点时,该组件都会保存活动窗口(具有焦点的窗口)的标题。

Now I'm planning to do the same using Mono C# on Linux.现在我打算在 Linux 上使用 Mono C# 做同样的事情。 Is it possible?是否有可能?

If yes, for what I'm looking for?如果是,我在寻找什么?

I decided to take a look at the source of gnome-screenshot which has a feature like this (to take a screenshot of the active window, only):我决定看一看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;
}

It has some logic to fallback to 'the window under the mouse pointer' when the above returns nothing:当上面没有返回任何内容时,它有一些逻辑可以回退到“鼠标指针下的窗口”:

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;
}

All of the above depends exclusive on libgdk-pixbuf as far as I can tell.据我所知,以上所有内容都依赖于 libgdk-pixbuf。 If that's not an option, you could always look at the implementation of those functions in the source of Gdk.如果这不是一个选项,您可以随时查看 Gdk 源代码中这些函数的实现。

i'm trying in linux using python to get the mouse clicked/focused window name/title. 我正在尝试在Linux中使用python来使鼠标单击/突出显示窗口名称/标题。 But i couldn't get any idea. 但是我一无所知。

or any other language can get the window name? 或任何其他语言都可以获取窗口名称? is it possible?is there is way for it ? 有可能吗?有办法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM