如何获得GNOME中活动窗口的监视器? [英] How do I get the monitor of an active window in GNOME?

查看:169
本文介绍了如何获得GNOME中活动窗口的监视器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对GNOME扩展开发非常陌生,并且由于缺乏API文档(或者可能是对我的互联网进行了秘密审查),我在使用它方面遇到了很多困难.我从修改现有扩展程序开始,以便更轻松地解决它.

I am very new to GNOME extension development, and I am having a hard time working with it, due to a profound lack of documentation (or maybe my Internet is clandestinely censored) of the API. I started by modifying an existing extension, so that it is easier to make my way around it.

问题是,我可以使用global.display.focus_window获取活动窗口,还可以使用Main.layoutManager.monitors获取连接到计算机的监视器列表.现在,我想做的是找出获得的窗口正坐在哪个显示器上(因此我可以将顶部面板移到该显示器上,因为这可能意味着我正在该显示器上工作).我尝试了各种操作,例如.screen,.monitor等,但均未成功.我还没有完成IntelliSense,我正在尝试猜测成员的身份,因为我似乎找不到任何文档.

The issue is, I can obtain the active window using global.display.focus_window, and also a list of monitors connected to the computer using Main.layoutManager.monitors. Now, what I would like to do, is find out which monitor the obtained window is sitting on (so I can move the top panel to that monitor, as it probably means I am working on that monitor at the moment). I tried various things, like .screen, .monitor etc., but with no success. I have no IntelliSense completion on this, and I am trying to guess what the members could be, as I cannot seem to find any docs on it.

我很欣赏GNOME的可定制性比我以前使用的(Unity,它根本不提供任何定制)要好得多,但是我不知道如何使用它,而且资源也很稀缺.我尝试研究源代码,但是我不熟悉源代码的组织方式,因此找不到声明所需的成员(如果存在)的相关代码部分.

I appreciate the fact that GNOME is way more customizable than what I used before (Unity, which provided no customization at all), but I don't know how to work with it and resources are scarce. I tried looking into the source code, but I am not familiar with how it is organized and I could not find the relevant portion of code where the members I need, if they exist, are declared.

我正在编码.js文件,所以我需要一些JavaScript代码.

I am coding the .js files, so I need some JavaScript code, I guess.

非常感谢您.

推荐答案

尽管Gnome Shell的大多数用户可见部分都是用JavaScript编写的,但这些通常只是底层C库的绑定.如果您使用的是Windows,Monitors和Screens,那么您将要参考Mutter文档以及Shell文档:

While most of the user-visible parts of Gnome Shell are written in JavaScript, these are often just bindings for the underlying C libraries. If you're working with Windows, Monitors and Screens then you're going to want to reference the Mutter documentation and probably the Shell documentation as well:

  • Mutter: https://developer.gnome.org/meta/stable/
  • Shell: https://developer.gnome.org/shell/stable/
  • St (Shell Toolkit): https://developer.gnome.org/st/stable/index.html

global对象上有一个名为screen(因此为global.screen)的属性,这无疑是具有功能MetaScreen meta/stable/MetaScreen.html#meta-screen-get-n-monitors"rel =" nofollow noreferrer> get_n_monitors() 以及get_primary_monitor()get_current_monitor()等.另一方面,MetaWindow包含一个名为 get_monitor() 会返回一个整数.我收集到监视器由整数引用,该整数传递给MetaScreenMetaWindow的各种函数,因为Mutter文档中似乎没有针对该对象的对象.

There is a property on the global object called screen (so global.screen) which is no doubt a MetaScreen which has a function get_n_monitors(), as well as get_primary_monitor(), get_current_monitor() and others. MetaWindow, on the other hand, contains a function called get_monitor() which returns an integer. I gather that monitors are referred to by integer number, which is passed to various functions of MetaScreen and MetaWindow, since there doesn't seem to be an object for that in the Mutter documentation.

您想要做的大多数相关JavaScript似乎都在 layout.js ,可能比我能提供的更好的例子说明了如何在Gnome Shell中使用Mutter.它还包括 Monitor 类,它似乎只是监视器索引的JS包装器.在此处中使用此类LayoutManager类(这是实例Main.layoutManager的定义).

Most of the related JavaScript for what you want to do seems to be in layout.js, which probably has better examples of how Mutter is used in Gnome Shell than I can give you. It also includes a Monitor class, which seems to just be a JS wrapper around the monitor index. This class is used here in the LayoutManager class (which is the definition of the instance Main.layoutManager).

关于文档的说明

最初,没有适当的" gnome-shell文档的原因是(内部JavaScript)API相当不稳定.要做的是,您没有一个稳定的API,但是您将以将要使用的相同语言来阅读源代码.在某些方面,这是有道理的,因为您可以修改live的prototype物体和猴子补丁一时兴起.

Originally, the rationale for not having "proper" gnome-shell documentation was that the (internal JavaScript) API was pretty unstable. The deal was, you don't get a stable API but you get to read the source in the same language you're going to write it in. In some ways this makes sense, given that you can modify the prototype of live objects and monkey-patch at whim.

API已经解决了很多,但是还没有人真正加紧编写脚本来自动记录它.我最好的建议是将Mutter,Shell和St文档添加为书签,并使用Gi​​thub或GitLab的搜索使事情变得更容易.

The API has settled down a lot, but no one has really stepped up to write a script to auto-document it, yet. My best advice would be to bookmark the Mutter, Shell and St documentation and use Github or GitLab's search to make things easier.

但是,这里有Gnome API的文档以及一些值得一看的内置模块:

There is however documentation for the Gnome API as well some of the built-in modules that are worth a skim:

  • Gnome API: https://devdocs.baznga.org/
  • Modules: https://gitlab.gnome.org/GNOME/gjs/wikis/Modules
  • General GObject usage in GJS: https://gitlab.gnome.org/GNOME/gjs/wikis/Mapping

这篇关于如何获得GNOME中活动窗口的监视器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆