임의의 창의 너비와 높이를 얻으려면 도구가 필요합니다.
이상적으로이 도구는 우분투 메뉴 막대의 크기를 공제합니다.
답변
귀하의 답변에서 편리한 GUI 도구를 찾고 있음을 이해합니다.
윈도우 의 순 크기와 실제 크기를 모두 얻을 수있는 작은 GUI 도구 (동적 업데이트)
으로는 “설명”에서 더 아래에 설명, 모두 wmctrl와 xdotool약간 잘못된 windowsize을 반환합니다.
아래의 스크립트 (표시기)는 패널에서 “실제”크기와 창의 순 크기를 모두 보여줍니다.
스크립트
#!/usr/bin/env python3
import signal
import gi
gi.require_version('AppIndicator3', '0.1')
gi.require_version('Gtk', '3.0')
import subprocess
from gi.repository import Gtk, AppIndicator3, GObject
import time
from threading import Thread
def get(cmd):
try:
return subprocess.check_output(cmd).decode("utf-8").strip()
except subprocess.CalledProcessError:
pass
# ---
# uncomment either one of two the lines below; the first one will let the user
# pick a window *after* the indicator started, the second one will pick the
# currently active window
# ---
window = get(["xdotool", "selectwindow"])
# window = get(["xdotool", "getactivewindow"])
class Indicator():
def __init__(self):
self.app = 'test123'
iconpath = "unity-display-panel"
self.indicator = AppIndicator3.Indicator.new(
self.app, iconpath,
AppIndicator3.IndicatorCategory.OTHER)
self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE)
self.indicator.set_menu(self.create_menu())
self.indicator.set_label(" ...Starting up", self.app)
# the thread:
self.update = Thread(target=self.show_seconds)
# daemonize the thread to make the indicator stopable
self.update.setDaemon(True)
self.update.start()
def create_menu(self):
menu = Gtk.Menu()
# separator
menu_sep = Gtk.SeparatorMenuItem()
menu.append(menu_sep)
# quit
item_quit = Gtk.MenuItem('Quit')
item_quit.connect('activate', self.stop)
menu.append(item_quit)
menu.show_all()
return menu
def show_seconds(self):
sizes1 = None
while True:
time.sleep(1)
sizes2 = self.getsize(window)
if sizes2 != sizes1:
GObject.idle_add(
self.indicator.set_label,
sizes2, self.app,
priority=GObject.PRIORITY_DEFAULT
)
sizes1 = sizes2
def getsize(self, window):
try:
nettsize = [int(n) for n in get([
"xdotool", "getwindowgeometry", window
]).splitlines()[-1].split()[-1].split("x")]
except AttributeError:
subprocess.Popen(["notify-send", "Missing data", "window "+window+\
" does not exist\n(terminating)"])
self.stop()
else:
add = [l for l in get(["xprop", "-id", window]).splitlines() if "FRAME" in l][0].split()
add = [int(n.replace(",", "")) for n in add[-4:]]
xadd = add[0]+add[1]; yadd = add[2]+add[3]
totalsize = [str(s) for s in [nettsize[0]+add[0]+add[1], nettsize[1]+add[2]+add[3]]]
displ_sizes = ["x".join(geo) for geo in [[str(s) for s in nettsize], totalsize]]
string = " "+displ_sizes[0]+" / "+displ_sizes[1]
return string+((25-len(string))*" ")
def stop(self, *args):
Gtk.main_quit()
Indicator()
GObject.threads_init()
signal.signal(signal.SIGINT, signal.SIG_DFL)
Gtk.main()
사용하는 방법
-
스크립트를 설치하려면 xdotool이 필요합니다.
sudo apt-get install xdotool -
스크립트를 빈 파일로 복사하여 다른 이름으로 저장하십시오.
getwindowsize.py -
다음 명령을 사용하여 터미널 창에서 스크립트를 테스트하십시오.
python3 /path/to/getwindowsize.py -
스크립트는 포커스 창 을 선택 하여 데코레이터 등을 포함 하여 순 창 크기 ( 와 모두의 출력에서
wmctrl와 같이xdotool)와 실제 창 크기 를 동적으로 표시합니다 .대상 창을 닫으면 표시기에 메시지가 표시됩니다.
-
모두 제대로 작동하면 바로 가기 키에 추가하십시오 : 시스템 설정> “키보드”> “바로 가기”> “사용자 정의 바로 가기”를 선택하십시오. “+”를 클릭하고 다음 명령을 추가하십시오.
python3 /path/to/getwindowsize.py
설명
wmctrl 및 xdotool 모두에 의해 표시되는 창 크기
… 약간 틀렸다
당신은 언급 :
이상적으로이 도구는 우분투 메뉴 막대의 크기를 빼줍니다.
전체 이야기는 모두이다 wmctrl -lG그리고 xdotool getwindowgeometry이 설명 될 때, 메뉴 표시 줄없이 창 크기를 반환하거나, 이 대답 :
일어나고있는 일은 wmctrl이 장식 내부의 창 지오메트리를 반환한다는 것입니다 (예 : 제목 표시 줄과 테두리 제외)
올바른 “실제”크기를 얻는 방법
정보를 올바르게 얻으려면 다음을 실행하십시오.
xprop -id <window_id> | grep FRAME
이것은 다음과 같이 출력됩니다 :
_NET_FRAME_EXTENTS(CARDINAL) = 0, 0, 28, 0
여기에서 우리는 우리가에서 출력으로, 윈도우의 크기에 추가 할 필요가있는 값을 얻을 wmctrl하고 xdotool창의 오른쪽 상단과 하단, 왼쪽으로.
즉,이 경우 wmctrla의 크기가 200×100이면 실제 크기는 200×128입니다.
노트
OP에서 제안한대로 사용자는 표시기를 시작한 후 다음을 바꾸어 창 을 선택할 수도 있습니다 .
window = get(["xdotool", "getactivewindow"])
으로:
window = get(["xdotool", "selectwindow"])
스크립트에서이 행 중 하나를 주석 해제 할 수 있습니다.
답변
wmctrl -lG다음 형식의 테이블에서 열려있는 모든 창의 목록을 얻는 데 사용할 수 있습니다 .
<window ID> <desktop ID> <x-coordinate> <y-coordinate> <width> <height> <client machine> <window title>
예제 출력은 다음과 같습니다.
$ wmctrl -lG
0x02a00002 0 -2020 -1180 1920 1080 MyHostName XdndCollectionWindowImp
0x02a00005 0 0 24 61 1056 MyHostName unity-launcher
0x02a00008 0 0 0 1920 24 MyHostName unity-panel
0x02a0000b 0 -1241 -728 1141 628 MyHostName unity-dash
0x02a0000c 0 -420 -300 320 200 MyHostName Hud
0x03a0000a 0 0 0 1920 1080 MyHostName Desktop
0x0400001d 0 61 24 1859 1056 MyHostName application development - A tool to get window dimensions - Ask Ubuntu - Mozilla Firefox
0x04200084 0 61 52 999 745 MyHostName Untitled Document 1 - gedit
답변
/unix/14159/how-do-i-find-the-window-dimensions-and-position-accurately-include-decorationxwininfo -all 에서 찾았습니다 .
작동하지만 더 편리한 솔루션 => 실시간 GUI 도구에 여전히 열려 있습니다.
답변
시도해 볼 수 있습니다 :
xdotool search --name gnome-panel getwindowgeometry
gnome-panel이라고 가정하면 우분투의 툴바의 프로세스 이름이지만 누가 아는가.
(가 필요할 수 있습니다 sudo apt-get install xdotool)
개선 된 GUI 기능을 위해 개선해야 할 사항은 다음과 같습니다.
zenity --text-info --filename=<(xprop)
포인터를 xprop의 십자가로 변경 한 다음 창을 클릭하면 GTK 대화 상자에 xprop의 정보가 인쇄됩니다.
답변
xwininfo와 그 장점
에 큰 문제 wmctrl와는 xdotool– 이러한 도구를 설치할 필요가있다 그들은 기본적으로 우분투에없는 . 그러나 우분투는와 함께 제공됩니다 xwininfo. 사용자가 선택한 창에 대한 정보를 제공하는 간단한 도구입니다.
간단한 사용법은 터미널 에 입력하고 xwininfo | awk '/Width/||/Height/'( awk출력을 필터링하는 데 사용되는 알림 ) 커서가 x원하는 GUI 창 을 선택하도록 변경되면 정보가 표시됩니다. 예를 들면 다음과 같습니다.
$ xwininfo | awk '/Width/||/Height/'
Width: 602
Height: 398
따라서 장점은 다음과 같습니다.
- 간단하다
- 기본적으로 설치됩니다
- 그것은 단지 텍스트입니다-화려하지 않으며 필요에 따라 필터링하고 조정할 수 있습니다
한 단계 더 xwininfo 가져 오기-활성 창의 속성 표시
물론 당신이 내가하는 것처럼 24/7 터미널을 연다면, 당신이 xwininfo필요한 전부입니다. 일부 사용자는 키보드 단축키를 선호 할 수 있습니다. 아래의 스크립트 (키보드 단축키에 바인드 됨)를 사용하면 현재 활성화 된 창에 대한 정보가있는 그래픽 팝업을 표시 할 수 있습니다. 스크린 샷에서 볼 수 있듯이 창 제목, 너비 및 높이 정보가 표시됩니다.
후드 아래에서 이것은 특히 장관을 이루지 않습니다. dbus서비스의 정보를 사용 xwininfo하여 간단한 팝업에 넣습니다. 소스 코드는 다음과 같습니다. 표준 스크립팅 규칙이 적용된다는 점을 명심하십시오. 실행 가능한 권한이 chmod +x있고 키보드 단축키에 바인딩 할 때 명령으로 스크립트 파일의 전체 경로를 지정하십시오.
#!/bin/bash
get_active_window()
{
qdbus org.ayatana.bamf \
/org/ayatana/bamf/matcher \
org.ayatana.bamf.matcher.ActiveWindow
}
get_active_name()
{
qdbus org.ayatana.bamf $1 \
org.ayatana.bamf.view.Name
}
main()
{
active_window=$(get_active_window)
active_xid=$( awk -F '/' '{print $NF}' <<< "$active_window" )
echo $active_xid
active_title=$(get_active_name $active_window)
dimensions=$(xwininfo -id "$active_xid" | awk '/Width/||/Height/')
text="$active_title\n""$dimensions"
zenity --info --text "$text" --width=200 --height=200
}
main $@
정보를 위해 Unity의 상단 패널 표시기 사용.
내 대답을 쓸 때 이것이 기존 프로젝트 중 하나 인 Ayatana Indicator에 통합하는 데 매우 유용한 기능이라는 것을 깨달았습니다. 이 표시기를 통해 GUI 창에 대한 모든 정보를 표시 할 수 있습니다. 현재도 활발한 개발이 진행 중입니다. 기하 정보 기능이 추가되었습니다 GitHub의 저장소 및에 방법에 내 개인 PPA . 물론 xwininfo약간 다른 방식으로 사용됩니다.



