में खुली एप्लिकेशन विंडो की संख्या प्राप्त करें मैं जानना चाहता हूं कि विंडो प्रबंधक द्वारा प्रबंधित एक विशिष्ट एप्लिकेशन के कितने उदाहरण खोले गए हैं। फिलहाल, मैं इस है:लिनक्स
#!/bin/bash
# wmctrl required
pids=$(pidof $1)
IFS=' ' read -a pid_arr <<< "$pids"
matches=0
for pid in "${pid_arr[@]}"
do
matching_lines=$(wmctrl -l -p | egrep -c "^.+\b.+\b$pid\b")
matches=$((matches + $matching_lines))
done
echo $matches
मैं फ़ायरफ़ॉक्स खुला तीन बार है और मैं एक तर्क के रूप firefox
पारित कहो, समारोह केवल सही संख्या वापस आ जाएगी अगर वहाँ थे कोई "उप खिड़कियों" (उदाहरण के लिए वरीयता खिड़कियां) खोला गया। अन्यथा, फ़ंक्शन इन विंडो को भी गिना जाएगा।
मैं "उप-विंडोज़" के बिना विंडोज़ की संख्या प्राप्त करना चाहता हूं।
पीएस .: कुछ बदलाव किए। उनकी संवाद-खिड़कियों के बिना खिड़कियों की संख्या की गणना करने के लिए, यह मेरे वर्तमान समाधान है:
#!/bin/bash
pids=$(pidof $1)
IFS=' ' read -r -a pid_arr <<< "$pids"
matches=0
for pid in "${pid_arr[@]}"
do
ids=$(wmctrl -l -p | awk '$3=='$pid'{printf $1" "}')
IFS=' ' read -r -a id_arr <<< "$ids"
for id in "${id_arr[@]}"
do
if ! xprop -id "$id" |
egrep -q '(WM_TRANSIENT_FOR|_NET_WM_WINDOW_TYPE_DIALOG)'
then
((matches++))
fi
done
done
echo $matches
लेकिन फ़ायरफ़ॉक्स के मामले में, स्क्रिप्ट ब्राउज़र विंडो और उसके वरीयता खिड़की के बीच भेद नहीं कर सकते क्योंकि उनमें से कोई भी एक है संवाद विंडो
उपर्युक्त स्क्रिप्ट मेरे लिए पर्याप्त है, क्योंकि मैं इसका उपयोग यह पता लगाने के लिए करता हूं कि xfce4-appfinder के कितने विंडोज़ (संवाद विंडो के बिना) खुले हैं। Xfce4-appfinder के लिए स्क्रिप्ट काम करता है, क्योंकि इसकी वरीयता विंडो को आसानी से एक संवाद विंडो के रूप में पहचाना जा सकता है। फ़ायरफ़ॉक्स में वरीयता विंडो को firefox -preferences
पर कॉल करके स्टैंडअलोन भी खोला जा सकता है। इस तरह की खिड़कियों को पहचानने के लिए किसी तरह की "सब-विंडो" शायद असंभव है।
xwininfo
(ब्राउज़र):
xwininfo: Window id: 0x1c0007f "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"
Root window id: 0xa1 (the root window) (has no name)
Parent window id: 0x1400048 (has no name)
1 child:
0x1c00080 (has no name):() 1x1+-1+-1 +1+37
Absolute upper-left X: 2
Absolute upper-left Y: 38
Relative upper-left X: 0
Relative upper-left Y: 14
Width: 956
Height: 511
Depth: 24
Visual: 0x20
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0x22 (installed)
Bit Gravity State: NorthWestGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no
Map State: IsViewable
Override Redirect State: no
Corners: +2+38 -962+38 -962-531 +2-531
-geometry 956x511+0+22
Bit gravity: NorthWestGravity
Window gravity: NorthWestGravity
Backing-store hint: NotUseful
Backing-planes to be preserved: 0xffffffff
Backing pixel: 0
Save-unders: No
Someone wants these events:
KeyPress
KeyRelease
ButtonPress
ButtonRelease
EnterWindow
LeaveWindow
PointerMotion
Exposure
VisibilityChange
StructureNotify
FocusChange
PropertyChange
Do not propagate these events:
Override redirection?: No
Window manager hints:
Client accepts input or input focus: Yes
Initial state is Normal State
Displayed on desktop 0
Window type:
Normal
Process id: 792 on host T530
Normal window size hints:
Program supplied minimum size: 300 by 71
Program supplied maximum size: 32767 by 32767
Program supplied window gravity: NorthWestGravity
No zoom window size hints defined
No window shape defined
No border shape defined
xwininfo
(वरीयताओं):
xwininfo: Window id: 0x1c046ef "Firefox Preferences"
Root window id: 0xa1 (the root window) (has no name)
Parent window id: 0x1400060 (has no name)
1 child:
0x1c046f0 (has no name):() 1x1+-1+-1 +961+37
Absolute upper-left X: 962
Absolute upper-left Y: 38
Relative upper-left X: 0
Relative upper-left Y: 14
Width: 956
Height: 1040
Depth: 24
Visual: 0x20
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0x22 (installed)
Bit Gravity State: NorthWestGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no0x1c00001
Map State: IsViewable
Override Redirect State: no
Corners: +962+38 -2+38 -2-2 +962-2
-geometry 956x1040-0-0
Bit gravity: NorthWestGravity
Window gravity: NorthWestGravity
Backing-store hint: NotUseful
Backing-planes to be preserved: 0xffffffff
Backing pixel: 0
Save-unders: No
Someone wants these events:
KeyPress
KeyRelease
ButtonPress
ButtonRelease
EnterWindow
LeaveWindow
PointerMotion
Exposure
VisibilityChange
StructureNotify
FocusChange
PropertyChange
Do not propagate these events:
Override redirection?: No
Window manager hints:
Client accepts input or input focus: Yes
Initial state is Normal State
Displayed on desktop 0
Window type:
Normal
Process id: 792 on host T530
Normal window size hints:
Program supplied location: 0, 0
Program supplied minimum size: 604 by 594
Program supplied maximum size: 32767 by 32767
Program supplied window gravity: NorthWestGravity
No zoom window size hints defined
No window shape defined
No border shape defined
यहाँ xprop
के अपने परिणाम और फ़ायरफ़ॉक्स के दोनों ब्राउज़र और वरीयता खिड़की के लिए xwininfo
हैं xprop
(ब्राउज़र):
_DESKTOP(CARDINAL) = 0
WM_STATE(WM_STATE):
window state: Normal
icon window: 0x0
WM_HINTS(WM_HINTS):
Client accepts input or input focus: True
Initial state is Normal State.
bitmap id # to use for icon: 0x1c00082
bitmap id # of mask for icon: 0x1c00083
window id # of group leader: 0x1c00001
_NET_STARTUP_ID(UTF8_STRING) = "xfce4-appfinder/|usr|lib|firefox|firefox/756-0-T530_TIME21351"
WM_WINDOW_ROLE(STRING) = "browser"
XdndAware(ATOM) = BITMAP
_MOTIF_DRAG_RECEIVER_INFO(_MOTIF_DRAG_RECEIVER_INFO) = 0x6c, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0
_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 29360257
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL
_NET_WM_USER_TIME(CARDINAL) = 1758669
_NET_WM_USER_TIME_WINDOW(WINDOW): window id # 0x1c00080
WM_CLIENT_LEADER(WINDOW): window id # 0x1c00001
_NET_WM_PID(CARDINAL) = 792
WM_LOCALE_NAME(STRING) = "en_US.UTF-8"
WM_CLIENT_MACHINE(STRING) = "T530"
WM_NORMAL_HINTS(WM_SIZE_HINTS):
program specified minimum size: 300 by 71
program specified maximum size: 32767 by 32767
window gravity: NorthWest
WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST
WM_CLASS(STRING) = "Navigator", "Firefox"
WM_ICON_NAME(STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"
_NET_WM_ICON_NAME(UTF8_STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"
WM_NAME(STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"
_NET_WM_NAME(UTF8_STRING) = "bash - Get number of opened application windows in linux - Stack Overflow - Mozilla Firefox"
xprop
(वरीयताओं)
_NET_WM_DESKTOP(CARDINAL) = 0
WM_STATE(WM_STATE):
window state: Normal
icon window: 0x0
WM_HINTS(WM_HINTS):
Client accepts input or input focus: True
Initial state is Normal State.
bitmap id # to use for icon: 0x1c046f2
bitmap id # of mask for icon: 0x1c046f3
window id # of group leader: 0x1c00001
WM_WINDOW_ROLE(STRING) = "Preferences"
XdndAware(ATOM) = BITMAP
_MOTIF_DRAG_RECEIVER_INFO(_MOTIF_DRAG_RECEIVER_INFO) = 0x6c, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0
_NET_WM_SYNC_REQUEST_COUNTER(CARDINAL) = 29378289
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL
_NET_WM_USER_TIME(CARDINAL) = 1456410
_NET_WM_USER_TIME_WINDOW(WINDOW): window id # 0x1c046f0
WM_CLIENT_LEADER(WINDOW): window id # 0x1c00001
_NET_WM_PID(CARDINAL) = 792
WM_LOCALE_NAME(STRING) = "en_US.UTF-8"
WM_CLIENT_MACHINE(STRING) = "T530"
WM_NORMAL_HINTS(WM_SIZE_HINTS):
program specified location: 0, 0
program specified minimum size: 604 by 594
program specified maximum size: 32767 by 32767
window gravity: NorthWest
WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS, _NET_WM_PING, _NET_WM_SYNC_REQUEST
WM_CLASS(STRING) = "Browser", "Firefox"
WM_ICON_NAME(STRING) = "Firefox Preferences"
_NET_WM_ICON_NAME(UTF8_STRING) = "Firefox Preferences"
WM_NAME(STRING) = "Firefox Preferences"
_NET_WM_NAME(UTF8_STRING) = "Firefox Preferences"
ऐसा कुछ काम कर सकता है 'xwininfo -tree -root | grep "मोज़िला फ़ायरफ़ॉक्स" | अजीब '{प्रिंट $ 1}' | xargs -n1 xwininfo -allid | | grep "प्रक्रिया आईडी" | सॉर्ट | uniq -c' –
कोई एप्लिकेशन क्या है?एप्लिकेशन का उदाहरण क्या है? क्या आप कठोर परिभाषा दे सकते हैं? एक विंडो प्रबंधक विंडोज़ का प्रबंधन करता है। मेरा विंडो प्रबंधक एप्लिकेशन नामक किसी भी इकाई के बारे में कुछ भी नहीं जानता है। आप खिड़कियों की गणना कर सकते हैं और उनके बारे में जानकारी प्राप्त कर सकते हैं। –
@ एनएम .: शायद मुझे "सामान्य विंडो" और "संवाद विंडो" नामों का उपयोग करना चाहिए, हालांकि मेरे पास कोई कठोर परिभाषा नहीं है। लेकिन 'xprop' कभी-कभी "संवाद" और "सामान्य" विंडो को अलग कर सकता है: यदि 'WM_TRANSIENT_FOR (विंडो) सेट किया गया है और/या' _NET_WM_WINDOW_TYPE (ATOM) = _NET_WM_WINDOW_TYPE_DIALOG' -> यह एक संवाद विंडो है। लेकिन फ़ायरफ़ॉक्स के मामले में, इसकी प्राथमिकता विंडो एक संवाद विंडो के रूप में पहचाने जाने योग्य नहीं है। – andreas1724