emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/hyperbole 943dba1 28/53: Added 'topwin' Python script t


From: Robert Weiner
Subject: [elpa] externals/hyperbole 943dba1 28/53: Added 'topwin' Python script to determine topmost app window at a screen position under macOS.
Date: Wed, 15 Nov 2017 22:47:03 -0500 (EST)

branch: externals/hyperbole
commit 943dba13b5a24778c88af80413c87224fe65bfbb
Author: Bob Weiner <address@hidden>
Commit: Bob Weiner <address@hidden>

    Added 'topwin' Python script to determine topmost app window at a screen 
position under macOS.
---
 Changes  |  2 ++
 MANIFEST |  1 +
 topwin   | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+)

diff --git a/Changes b/Changes
index 35cebdb..4a47140 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,5 @@
+----
+
 2017-10-16  Bob Weiner  <address@hidden>
 
 * hib-debbugs.el (debbugs-query:at-p): eliminated match of #id-number and 
always required
diff --git a/MANIFEST b/MANIFEST
index 250ba99..a1cbfcd 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -87,6 +87,7 @@ hsettings.el        - Hyperbole settings which may require 
customization
 hvar.el             - Variable manipulation routines for GNU Hyperbole
 hyperbole-banner.png- Graphic of GNU Hyperbole for display with About Hyperbole
 smart-clib-sym      - Test whether symbol appears within a set of C libraries
+topwin              - Python script to find the topmost macOS app window at a 
screen position
 .hypb & _hypb       - Button data files used by the Hyperbole DEMO file
 
 --- EXTERNAL SYSTEM ENCAPSULATIONS ---
diff --git a/topwin b/topwin
new file mode 100755
index 0000000..b6f3dce
--- /dev/null
+++ b/topwin
@@ -0,0 +1,46 @@
+#!python2
+#
+# SUMMARY:      Outputs the [application name] of the topmost window at mouse 
screen position or nothing if none
+# USAGE:        <script> <x-screen-coordinate> <y-screen-coordinate>
+#
+# REQUIRES:     macOS window system and the python2 and the PyObjC libraries 
available here: https://pythonhosted.org/pyobjc/install.html
+#
+# AUTHOR:       Bob Weiner <address@hidden>
+# ORIG-DATE:    14-Oct-17 at 16:21:53
+#
+# DESCRIPTION:  
+# DESCRIP-END.
+
+import Quartz
+from sys import argv, exit
+
+if len(argv) < 3:
+    print "%s: ERROR - Call with 2 numeric arguments, X and Y representing an 
absolute screen position" % argv[0]
+    exit(1)
+
+x = int(argv[1]); y = int(argv[2])
+
+# Return the first window only that x,y falls within since the windows are 
listed in z-order (top of stack to bottom)
+def filter_and_print_top_window(x, y):
+    win_x = win_y = win_width = win_height = 0
+
+    for v in Quartz.CGWindowListCopyWindowInfo( 
Quartz.kCGWindowListOptionOnScreenOnly | 
Quartz.kCGWindowListExcludeDesktopElements, Quartz.kCGNullWindowID ):
+        val = v.valueForKey_
+        bounds_val = val('kCGWindowBounds').valueForKey_
+        
+        # If item has a non-zero WindowLayer, it is not an app and is probably 
system-level, so skip it.
+        if not val('kCGWindowIsOnscreen') or val('kCGWindowLayer'):
+            continue
+
+        win_x = int(bounds_val('X')); win_y = int(bounds_val('Y'))
+        win_width = int(bounds_val('Width')); win_height = 
int(bounds_val('Height'))
+
+        if win_x <= x and x < win_x + win_width and win_y <= y and y < win_y + 
win_height:
+            print ('[' + ((val('kCGWindowOwnerName') or '') + 
']')).encode('utf8')
+            # Add this line back in if you need to see the specific window 
within the app at the given position.
+            # + ('' if val('kCGWindowName') is None else (' ' + 
val('kCGWindowName') or '')) \
+
+            break
+
+# Filter to just the topmost window at (x,y) screen coordinates and print the 
bracketed [window name], if any.
+filter_and_print_top_window(x, y)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]