准备弄脏您的手
在我认为可以要求用户做的事情的边缘,但是,另一方面,当说明明确时,为什么不这样做呢?所以我们开始...
设置应在哪个监视器上显示新窗口的后台进程
瓦拉片段
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();
}
}
Vala代码段需要进行编译。为此,您需要安装一些东西:
sudo apt install valac libwnck-3-dev libgtk-3-dev
复制以下代码段,另存为 win_tomonitor.vala
使用以下命令编译代码段:
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参数很愚蠢,但是需要),将在工作目录中生成一个可执行文件。
- 通过
xrandr
在终端中运行命令来查找主监视器的名称。
以目标监视器为参数运行可执行文件,例如
/path/to/win_tomonitor HDMI-1
新(“正常”)窗口将出现在目标监视器左上角100px(x + y)处。
NB
将其添加为启动项时,可能需要在运行前添加几秒钟的时间。如果您在登录/启动时遇到问题,请提及。
编辑
在经过编辑的版本下方(应要求提供)。差异:
安装程序与第一个版本完全相同。玩得开心!
找出视窗的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();
}
}