AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1108654
Accepted
LeonidMew
LeonidMew
Asked: 2019-01-11 09:34:55 +0800 CST2019-01-11 09:34:55 +0800 CST 2019-01-11 09:34:55 +0800 CST

如何始终在特定显示器上启动应用程序?

  • 772

我有双显示器配置,并希望所有新旧应用程序都在右侧的主显示器上启动。但是有些应用程序会在第二个屏幕上启动,无论焦点/鼠标指针在哪里。我认为这是因为 top:left corner 0:0 在第二个显示器上。它比主要的更大,这可能是一个原因吗?

次要的是我运行 kodi 的电视,它有一个选择显示的设置。

可能有一些应用程序会记住每个应用程序的位置和显示,并且在第二个关闭时也要小心 - 意思是记住位置直到显示器再次打开。在早期版本的 ubuntu compiz 中这样做,但没有更多。

更新:将 DE 更改为肉桂

multiple-monitors window-manager window cinnamon 18.04
  • 1 1 个回答
  • 4020 Views

1 个回答

  • Voted
  1. Best Answer
    Jacob Vlijm
    2019-04-10T10:45:41+08:002019-04-10T10:45:41+08:00

    准备好弄脏你的手
    在我觉得我们可以要求用户做的边缘,但另一方面,当说明很清楚时,为什么不呢?所以我们开始...


    后台进程设置应在哪个监视器上显示新窗口

    Vala 片段

    using Wnck;
    using Gdk;
    using Gtk;
    
    // compile:
    // valac --pkg gtk+-3.0 --pkg gio-2.0 --pkg libwnck-3.0 -X "-D WNCK_I_KNOW_THIS_IS_UNSTABLE" 'file.vala'
    
    namespace move_newwins {
    
        private int[] monitor_geo_x;
        private int[] monitor_geo_y;
        private int monitorindex;
        private string currmon;
    
        private void getwins() {
            var dsp = Gdk.Display.get_default();
            unowned Wnck.Screen scr = Wnck.Screen.get_default();
            scr.force_update();
            get_monitors(dsp);
            scr.window_opened.connect(newwin);
        }
    
        private void newwin (Wnck.Window newwin) {
            newwin.unmaximize();
            int winx;
            int winy;
            int winwidth;
            int winheight;
            newwin.get_geometry(out winx, out winy, out winwidth, out winheight);
            Wnck.WindowType type = newwin.get_window_type();
            if (type == Wnck.WindowType.NORMAL) {
                newwin.set_geometry(
                    Wnck.WindowGravity.NORTHWEST,
                    Wnck.WindowMoveResizeMask.X |
                    Wnck.WindowMoveResizeMask.Y |
                    Wnck.WindowMoveResizeMask.WIDTH |
                    Wnck.WindowMoveResizeMask.HEIGHT,
                    monitor_geo_x[monitorindex] + 100,
                    monitor_geo_y[monitorindex] + 100,
                    winwidth, winheight
                );
            }
        }
    
        private int get_stringindex (string s, string[] arr) {
            for (int i=0; i < arr.length; i++) {
                if(s == arr[i]) return i;
            } return -1;
        }
    
        private void get_monitors(Gdk.Display dsp) {
            int nmons = dsp.get_n_monitors();
            string[] monitornames = {};
            for (int i=0; i < nmons; i++) {
                Gdk.Monitor newmon = dsp.get_monitor(i);
                monitornames += newmon.get_model();
                Rectangle geo = newmon.get_geometry();
                monitor_geo_x += geo.x;
                monitor_geo_y += geo.y;
                monitorindex = get_stringindex(
                    currmon, monitornames
                );
            }
        }
    
        public static void main (string[] args) {
            currmon = args[1];
            Gtk.init(ref args);
            getwins();
            Gtk.main();
        }
    }
    
    1. 需要编译 Vala 代码段。为此,您需要安装一些东西:

      sudo apt install valac libwnck-3-dev libgtk-3-dev
      
    2. 复制下面的代码片段,另存为win_tomonitor.vala

    3. 使用以下命令编译代码段:

      valac --pkg gtk+-3.0 --pkg gio-2.0 --pkg libwnck-3.0 -X "-D WNCK_I_KNOW_THIS_IS_UNSTABLE" '/path/to/win_tomonitor.vala' 
      

      (我知道, wnck 参数很愚蠢,但需要),将在工作目录中生成一个可执行文件。

    4. xrandr通过在终端中运行命令找出主监视器的名称。
    5. 以目标监视器作为参数运行可执行文件,例如

      /path/to/win_tomonitor HDMI-1
      

    新(“正常”)窗口将出现在目标监视器左上角 100 像素 (x + y) 处。

    注意

    将此添加为启动项时,您可能需要在运行它之前添加几秒钟的休息时间。如果您在登录/启动时遇到问题,请提及。


    编辑

    低于编辑版本(根据要求)。差异:

    • 此版本跳过已在目标监视器上的窗口上的操作。
    • 此版本允许设置排除WM_CLASS-es。要排除一个或多个类:在目标 monitor- 参数之后添加额外的参数。一个例子:

      /path/to/win_tomonitor HDMI-1 Tilix Gedit
      

      从移动中排除 Tilix 和 gedit 窗口。

    设置与第一个版本完全相同。玩得开心!

    找出一个窗口的 WM_CLASS

    • 打开终端窗口
    • 键入xprop,按Return
    • 点击目标窗口,WM_CLASS出现在终端

    编码

    using Wnck;
    using Gdk;
    using Gtk;
    
    // compile:
    // valac --pkg gtk+-3.0 --pkg gio-2.0 --pkg libwnck-3.0 -X "-D WNCK_I_KNOW_THIS_IS_UNSTABLE" 'file.vala'
    
    namespace move_newwins {
    
        private int[] monitor_geo_x;
        private int[] monitor_geo_y;
        private int monitorindex;
        private string currmon;
        Gdk.Display dsp;
        string[] blacklist;
    
        private void getwins() {
            dsp = Gdk.Display.get_default();
            unowned Wnck.Screen scr = Wnck.Screen.get_default();
            scr.force_update();
            get_monitors(dsp);
            scr.window_opened.connect(newwin);
        }
    
        private void newwin (Wnck.Window newwin) {
            newwin.unmaximize();
            int winx;
            int winy;
            int winwidth;
            int winheight;
            newwin.get_geometry(out winx, out winy, out winwidth, out winheight);
            string wins_monitor = dsp.get_monitor_at_point(winx, winy).get_model();
            Wnck.WindowType type = newwin.get_window_type();
            string wm_class = newwin.get_class_group_name();
            bool blacklisted = get_stringindex(wm_class, blacklist) != -1;
    
            if (
                type == Wnck.WindowType.NORMAL &&
                wins_monitor != currmon &&
                !blacklisted
            ) {
                newwin.set_geometry(
                    Wnck.WindowGravity.NORTHWEST,
                    Wnck.WindowMoveResizeMask.X |
                    Wnck.WindowMoveResizeMask.Y |
                    Wnck.WindowMoveResizeMask.WIDTH |
                    Wnck.WindowMoveResizeMask.HEIGHT,
                    monitor_geo_x[monitorindex] + 100,
                    monitor_geo_y[monitorindex] + 100,
                    winwidth, winheight
                );
            }
        }
    
        private int get_stringindex (string s, string[] arr) {
            for (int i=0; i < arr.length; i++) {
                if(s == arr[i]) return i;
            } return -1;
        }
    
        private void get_monitors(Gdk.Display dsp) {
            int nmons = dsp.get_n_monitors();
            string[] monitornames = {};
            for (int i=0; i < nmons; i++) {
                Gdk.Monitor newmon = dsp.get_monitor(i);
                monitornames += newmon.get_model();
                Rectangle geo = newmon.get_geometry();
                monitor_geo_x += geo.x;
                monitor_geo_y += geo.y;
                monitorindex = get_stringindex(
                    currmon, monitornames
                );
            }
        }
    
        public static void main (string[] args) {
            currmon = args[1];
            blacklist = args[1:args.length];
            Gtk.init(ref args);
            getwins();
            Gtk.main();
        }
    }
    
    • 14

相关问题

  • 可以将窗口(例如浏览器窗口)的大小限制为精确的像素尺寸吗?

  • gnome-mplayer 使用 xineramascreen 选项在第二个屏幕上播放

  • 使用带有两屏设置的 Ubuntu

  • 自 10.04 起,笔记本电脑的扩展显示器显示摇晃/波动的图像 [关闭]

  • 有没有办法在 Ubuntu a la Windows 中拥有扩展桌面?[关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve