简体   繁体   English

如何为新浏览器 window 指定几何图形(例如 1280x720)?

[英]How to specify geometry (e.g. 1280x720) for a new browser window?

Ubuntu Studio Linux 14.04.1 LTS Ubuntu 工作室 Linux 14.04.1 LTS

From a Linux shell script , I'd like to launch a browser window of an exact size, eg as a step for automatically recording a screencast.从 Linux shell 脚本,我想启动一个精确大小的浏览器 window,例如作为自动录制截屏视频的一个步骤。

My first thought was to use Xwindows -geometry setting, which once upon a time was common to all apps in Xwindows and was preserved in Gnome options我的第一个想法是使用 Xwindows -geometry设置,曾几何时,它对 Xwindows 中的所有应用程序都是通用的,并保留在Gnome 选项

#!/bin/bash -e
chromium-browser -geometry 1280x720 # ignores the spec
# firefox -geometry 1280x720 ignores the spec too

I found this post in the FreeBSD forum which also says that firefox ignores the -geometry setting.我在 FreeBSD 论坛中找到了这篇文章,其中还说 firefox 忽略了-geometry设置。 The recommendation was to use Javascript on startup, like this:建议在启动时使用 Javascript,如下所示:

% firefox javascript:%20resizeTo\(1280,720\)

to call window.resizeTo() in JS.在 JS 中调用window.resizeTo() Testing, that doesn't work either.测试,这也不起作用。 The linked page from MDN notes that with a few exceptions, this will not work post Firefox 7.来自 MDN 的链接页面指出,除了少数例外,这在 Firefox 7 之后不起作用。

@helloV pointed me to: Launch Google Chrome from the command line with specific window coordinates @helloV 指出我: 使用特定的 window 坐标从命令行启动 Google Chrome

which is about position not size.这大约是 position 不是大小。 Nevertheless, digging through it yielded these ideas that also don't work然而,通过挖掘它产生了这些同样行不通的想法

NO:不:

chromium-browser --window-size=800,600
chromium-browser --window-size="800,600"
chromium-browser --window-size=800x600
chromium-browser -window-size=800,600
chromium-browser -window-size=800x600

We could always read the Firefox Command Line Options page (hint: window size isn't there) or the Chrome switches source code , where we will find --window-size=w,h and that was tried above.我们总是可以阅读Firefox 命令行选项页面(提示:window 大小不存在)或Chrome 开关源代码,我们将在其中找到--window-size=w,h并且上面已尝试过。

From: setting the window dimensions of a running application and a reading of man xdotool :来自: 设置正在运行的应用程序的 window 尺寸和阅读man xdotool

This will resize a window after clicking it to select:单击它后,这会将 window 调整为 select:

xdotool selectwindow windowsize 1280 720

Is there anything simpler or cleaner to start a browser window of specified pixel dimensions?启动指定像素尺寸的浏览器 window 有什么更简单或更清洁的方法吗?

I don't know if you can start a web browser with a specified size but you can resize it after with wmctrl but i guess it is similar to xdotool method (without click) so it's maybe not what your are looking for. 我不知道您是否可以启动具有指定大小的Web浏览器,但是可以在使用wmctrl之后重新设置它的大小,但是我想它类似于xdotool方法(无需单击),因此它可能不是您想要的。

Eg 例如

#!/bin/sh

wid=`wmctrl -l | grep Firefox | grep "Stack Overflow" | cut -d " " -f 1`
wmctrl -i -r $wid -e 0,0,0,800,600 -b remove,maximized_vert,maximized_horz

If you've got only one window : 如果只有一个窗口:

wmctrl -r mozilla -e 0,0,0,800,600 -b remove,maximized_vert,maximized_horz

-e -> gravity,left,up,width,height -e->重力,左,上,宽,高
-r -> Id with -i or window name -r->具有-i或窗口名称的ID
-b -> unmaximize the window, otherwise resize will not works -b->最大化窗口,否则无法调整大小

EDIT 编辑

I think you can't use PID because for example with firefox you will have only one PID even if you've got more than one window, but if your are sure that is not the case you can do something like this (i think it will works): 我认为您不能使用PID,因为例如使用firefox,即使您拥有多个窗口,您也将只有一个PID,但是如果您确定不是这种情况,则可以执行以下操作(我认为是这样)将起作用):

PID=....
wid=`wmctrl -lp | grep " $PID " | cut -d " " -f 1`
wmctrl -i -r $wid -e 0,0,0,800,600 -b remove,maximized_vert,maximized_horz

wmctrl -lp seems to list windows in opened order (really not sure about that), so you can use tail -n 1 to get only the last window with the PID you are looking for. wmctrl -lp似乎以打开的顺序列出了窗口(真的不太确定),因此您可以使用tail -n 1仅获取您要查找的PID的最后一个窗口。

wid=`wmctrl -lp | grep " $PID " | tail -n 1 | cut -d " " -f 1`

As listed here => https://peter.sh/experiments/chromium-command-line-switches/ 如此处所列=> https://peter.sh/experiments/chromium-command-line-switches/

Sets the initial window size. 设置初始窗口大小。 Provided as string in the format "800,600". 以字符串形式提供,格式为“ 800,600”。

command: firefox -width xxx -height yyy -P profile命令: firefox -width xxx -height yyy -P profile

It works for me on condition I specify a profile on the command ( -P ppp ).它适用于我在命令 ( -P ppp ) 上指定配置文件的条件。

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

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