サイネージというほどのものではないけど、それ的なもののソフトウェアをつくるために、X上で外部プロセスのウィンドウをいじってどうにかするみたいなのを探した。
いろいろ当り最終的にlibwnckを見つけた。ウィンドウマネージャの操作ライブラリ。Pythonバインディングのpython-libwnckもある。
import wnck, gtk screen = wnck.screen_get_default() screen.force_update() windows = screen.get_windows()
これでウィンドウリスト (WnckWindowのリスト) が得られる。これに対して、
w = windows[0] w.get_name() # Window Name w.get_application().get_name() # Application Name w.get.get_class_group().get_name() # Class Name
こんな感じで情報を取得し、
w.set_geometry(wnck.WINDOW_GRAVITY_CURRENT, wnck.WINDOW_CHANGE_X | wnck.WINDOW_CHANGE_Y, 100,100,0,0) w.set_title("新しいタイトル") gdk_w = gtk.gdk.window_foreign_new(w.get_xid()) gdk_w.set_decorations(0) # デコレーションの削除 # 反映させる gtk.gdk.window_process_all_updates() gtk.gdk.flush()
こんな感じにウィンドウが操作できる。
uWSGIと併用時のエラー
ちなみに、python-wnckを使用するWebアプリをuwsgi上で動かしたらこんな感じのエラーが出てしばらくこまった。
172.29.4.50 - - [12/Mar/2014:22:59:39] "GET /info HTTP/1.1" 200 4 "" "Mozilla/5.0 (X11; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0" [pid: 15271|app: 0|req: 6/6] *.*.*.* () {32 vars in 508 bytes} [Wed Mar 12 22:59:39 2014] GET /set_center/info => generated 4 bytes in 6 msecs (HTTP/1.1 200) 4 headers in 138 bytes (1 switches on core 0) Wed Mar 12 22:59:41 2014 - !!! uWSGI process 15270 got Segmentation Fault !!! Wed Mar 12 22:59:41 2014 - *** backtrace of 15270 *** Wed Mar 12 22:59:41 2014 - uwsgi(uwsgi_backtrace+0x25) [0x431ea5] Wed Mar 12 22:59:41 2014 - uwsgi(uwsgi_segfault+0x21) [0x431f81] Wed Mar 12 22:59:41 2014 - /lib/x86_64-linux-gnu/libc.so.6(+0x324f0) [0x7fa477a794f0] Wed Mar 12 22:59:41 2014 - /usr/lib/libstartup-notification-1.so.0(sn_xcb_display_new+0x109) [0x7fa47201fa89] Wed Mar 12 22:59:41 2014 - /usr/lib/libstartup-notification-1.so.0(sn_display_new+0x2d) [0x7fa47201fb3d] Wed Mar 12 22:59:41 2014 - /usr/lib/libwnck-1.so.22(wnck_screen_get+0x117) [0x7fa474660617] Wed Mar 12 22:59:41 2014 - /usr/lib/python2.7/dist-packages/gtk-2.0/wnck.so(+0xa809) [0x7fa4748ac809] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x56fd) [0x7fa47521d04d] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5b7b) [0x7fa47521d4cb] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x848) [0x7fa47521e2e8] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(+0xa6917) [0x7fa475274917] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x4e) [0x7fa475303d3e] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(+0x184810) [0x7fa475352810] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x4e) [0x7fa475303d3e] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_CallObjectWithKeywords+0x47) [0x7fa475304647] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyInstance_New+0x7b) [0x7fa4752ec58b] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x4e) [0x7fa475303d3e] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x2a57) [0x7fa47521a3a7] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5b7b) [0x7fa47521d4cb] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x848) [0x7fa47521e2e8] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(+0xa6917) [0x7fa475274917] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x4e) [0x7fa475303d3e] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x2a57) [0x7fa47521a3a7] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x848) [0x7fa47521e2e8] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(+0xa6917) [0x7fa475274917] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x4e) [0x7fa475303d3e] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(+0x184810) [0x7fa475352810] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x4e) [0x7fa475303d3e] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(+0x11c1ac) [0x7fa4752ea1ac] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x4e) [0x7fa475303d3e] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x2a57) [0x7fa47521a3a7] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalCodeEx+0x848) [0x7fa47521e2e8] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(+0xa6806) [0x7fa475274806] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x4e) [0x7fa475303d3e] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(+0x184810) [0x7fa475352810] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x4e) [0x7fa475303d3e] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(+0xcbdf6) [0x7fa475299df6] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyObject_Call+0x4e) [0x7fa475303d3e] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x27dd) [0x7fa47521a12d] Wed Mar 12 22:59:41 2014 - /usr/lib/libpython2.7.so.1.0(PyEval_EvalFrameEx+0x5b7b) [0x7fa47521d4cb] Wed Mar 12 22:59:41 2014 - *** end of backtrace *** Wed Mar 12 22:59:41 2014 - DAMN ! worker 2 (pid: 15270) died :( trying respawn ... Wed Mar 12 22:59:41 2014 - Respawned uWSGI worker 2 (new pid: 15296)
最初はなんかcherrypyかuWSGIのスレッドが有効になっちゃってて変な事がおこっているかと思ったけど、どうやらPython初期化後にforkしてからGTKとかX11のAPI使っているから発生しているよう。(断定的に調べていないので違うかも。)
uWSGIのlazyオプションを指定するとfork後の初期化になるようなので、それで改善した。