This week, I observed someone working on Linux struggling with copying and pasting SQL code from Emacs to a Firefox textarea. The Ctrl+C/Ctrl+V way of doing things (which I first saw on Windows, don't know who "invented" it) is nice, but once you tried the X11 way of copy and paste (using the X selection), you will never want to live without it. Being a happy user of X11 copy/paste for some years now, here's a short note for all who have not yet tried this great feature :)
To copy some text, simply select it with the mouse (no, really - just select it, no keystrokes). To paste the text you just selected, middle-click with your mouse directly where you want to paste the text - the text will be copied! As clipboard handling in Linux/X11 was (is?) a bit inconsistent, there might be some things to watch out for. For example you can only paste the selected text if the window in which you selected the text is still open.
Once you get used to that, it's really useful and you can work more productively. Nice side-effect: You can middle-click inside an open tab in firefox and have the URL in the X selection get loaded in this tab. So, to open a URL from a text file (or similiar), just select the URL, open a new tab in Firefox (or use an existing one) and middle-click inside the content area of the tab. Firefox will load the URL you just "pasted". Simple.
Showing posts with label x11. Show all posts
Showing posts with label x11. Show all posts
Saturday, December 8, 2007
Thursday, September 13, 2007
X11 idle time and focused window in Python
For my Evolution New Mail Notification script, I wanted to make the notification popups not enabled when I'm already working within evolution (e.g. the Evolution window is focused) and I also didn't want to play sounds when I'm working on the computer, because I will see the visual notification, anyway (e.g. the X11 idle time is less than some specified timeout).
To accomplish that, I had to write a bit of Python code for two simple tasks:
Window Name and Class for the focused window
To accomplish that, I had to write a bit of Python code for two simple tasks:
- Get the window name and/or class of the currently focused window
- Get the idle time of the X11 session, e.g. the time since the last input event
Window Name and Class for the focused window
import Xlib.displayX11 Idle Time using the XScreenSaver extension
display = Xlib.display.Display()
focus = display.get_input_focus()
print "WM Class: %s" % ( focus.focus.get_wm_class(), )
print "WM Name: %s" % ( focus.focus.get_wm_name(), )
import ctypesIf you're interested in a real-world example usage of this code, feel free to check out my evolution-newmail.py new mail notification script that works with Evolution over D-BUS.
import os
class XScreenSaverInfo( ctypes.Structure):
""" typedef struct { ... } XScreenSaverInfo; """
_fields_ = [('window', ctypes.c_ulong), # screen saver window
('state', ctypes.c_int), # off,on,disabled
('kind', ctypes.c_int), # blanked,internal,external
('since', ctypes.c_ulong), # milliseconds
('idle', ctypes.c_ulong), # milliseconds
('event_mask', ctypes.c_ulong)] # events
xlib = ctypes.cdll.LoadLibrary( 'libX11.so')
dpy = xlib.XOpenDisplay( os.environ['DISPLAY'])
root = xlib.XDefaultRootWindow( dpy)
xss = ctypes.cdll.LoadLibrary( 'libXss.so')
xss.XScreenSaverAllocInfo.restype = ctypes.POINTER(XScreenSaverInfo)
xss_info = xss.XScreenSaverAllocInfo()
xss.XScreenSaverQueryInfo( dpy, root, xss_info)
print "Idle time in milliseconds: %d" % ( xss_info.contents.idle, )
Subscribe to:
Posts (Atom)