본문 바로가기

좋아하는 것_매직IT/96.IT 핫이슈

AHK_X11 - AutoHotkey for Linux 를 소개합니다 (github.com/phil294)

반응형

AHK_X11 - AutoHotkey for Linux 를 소개합니다 

깃허브에서 AutoHotkey 는 아래와 같이 소개하고 있군요..
AutoHotkey is "Powerful. Easy to learn. The ultimate automation scripting language for Windows.". This project tries to bring large parts of that to Linux.

해당 AHK_X11에 대한 개념에 대해서는 머릿속에는 아래 내용을 넣어두시면 좋을것 같네요..

AutoHotkey는 "강력하고 배우기 쉽습니다. Windows를 위한 최고의 자동화 스크립팅 언어입니다."입니다. 
이 프로젝트는 그 중 상당 부분을 Linux로 가져오려고 합니다.라고요..

개발관련해서 알아보니..아래와 같이 진행하시면 되고요..

Development

These are the steps required to build this project locally, such as if you want to contribute to the project. Please open an issue if anything doesn't work.

You don't need to follow this steps to use AHK_X11, for that, please see Installation above.

  1. Install development versions of prerequisites.
    1. Ubuntu 20.04 and up:
      1. Dependencies 
      2. sudo apt-get install libxinerama-dev libxkbcommon-dev libxtst-dev libgtk-3-dev libxi-dev libx11-dev libgirepository1.0-dev
        
      3. Install Crystal and Shards (Shards is typically included in Crystal installation)
    2. Arch Linux:
      sudo pacman -S crystal shards gcc libxkbcommon libxinerama libxtst gtk3 gc
      
  2. git clone https://github.com/phil294/AHK_X11
  3. cd AHK_X11
  4. Run these commands one by one (I haven't double checked them, so it's best to go through them manually). Most of it is all WIP and temporary and only necessary so the different dependencies get along fine (x11 and gobject bindings). As a bonus, the build_namespace invocations cache the GIR (require_gobject calls) and thus reduce the overall compile time from ~6 to ~3 seconds.
    shards install
    # populate cache
    crystal run lib/gobject/src/generator/build_namespace.cr -- Gtk 3.0 > lib/gobject/src/gtk/gobject-cache-gtk.cr
    crystal run lib/gobject/src/generator/build_namespace.cr -- xlib 2.0 > lib/gobject/src/gtk/gobject-cache-xlib--modified.cr
    for lib in "GObject 2.0" "GLib 2.0" "Gio 2.0" "GModule 2.0" "Atk 1.0" "freetype2" "HarfBuzz 0.0" "GdkPixbuf 2.0" "cairo 1.0" "Pango 1.0" "Gdk 3.0"; do
        echo "### $lib" >> lib/gobject/src/gtk/gobject-cache-gtk-other-deps.cr
        crystal run lib/gobject/src/generator/build_namespace.cr -- $lib >> lib/gobject/src/gtk/gobject-cache-gtk-other-deps.cr
    done
    # update lib to use cache
    sed -i -E 's/^(require_gobject)/# \1/g' lib/gobject/src/gtk/gobject-cache-gtk.cr lib/gobject/src/gtk/gobject-cache-gtk-other-deps.cr
    sed -i -E 's/^require_gobject "Gtk", "3.0"$/require ".\/gobject-cache-gtk"/' lib/gobject/src/gtk/gtk.cr
    echo 'require "./gobject-cache-xlib--modified"' > tmp.txt; echo 'require "./gobject-cache-gtk-other-deps"' >> tmp.txt; cat lib/gobject/src/gtk/gobject-cache-gtk.cr >> tmp.txt; mv tmp.txt lib/gobject/src/gtk/gobject-cache-gtk.cr
    echo 'macro require_gobject(namespace, version = nil) end' >> lib/gobject/src/gobject.cr
    # delete conflicting c function binding by modifying the cache
    sed -i -E 's/  fun open_display = XOpenDisplay : Void$//' lib/gobject/src/gtk/gobject-cache-xlib--modified.cr
    # https://github.com/jhass/crystal-gobject/issues/103
    sed -i -E 's/(def self.new_from_stream.+: self)$/\1?/g' lib/gobject/src/gtk/gobject-cache-gtk-other-deps.cr
  5. Now everything is ready for local use with shards build -Dpreview_mt, if you have libxdo (xdotool) version 2016x installed. Read on for a cross-distro compatible build.
  6. In lib/x_do/src/x_do/libxdo.cr, add line role : LibC::Char* after winname : LibC::Char*
  7. add xdo_quit_window TODO: Waiting for a PR on x_do.cr, so for now, probably best just comment out the failing lines later on in win-close and win-maximize and win-restore
  8. add xdo_set_state TODO: same as above
  9. To make AHK_X11 maximally portable, various dependencies should be statically linked. This is especially important because of the script compilation feature: You can use the binary to transform a script into a new stand-alone binary, and that resulting binary should be portable across various Linux distributions without ever requiring the user to install any dependencies. Here is an overview of all dependencies. All of this was tested on Ubuntu 18.04.
    • Should be statically linked:
      • libxdo. Additionally to the above reasons, it isn't backwards compatible (e.g. Ubuntu 18.04 and 20.04 versions are incompatible) and may introduce even more breaking changes in the future. Also, we fix a rarely occurring fatal error here (probably Crystal-specific?). So,
        • clone xdotool somewhere, in there,
        • in xdo.c, after data = xdo_get_window_property_by_atom(xdo, wid, request, &nitems, &type, &size);, add another if(data == NULL) return XDO_ERROR;
        • run make clean && make libxdo.a and then copy the file libxdo.a into our static folder (create if it doesn't exist yet).
      • Dependencies of libxdo: libxkbcommon, libXtst and libXi. The static libraries should be available from your package manager dependencies installed above so normally there's nothing you need to do.
      • More dependencies of libxdo which are also available from the packages, but their linking fails with obscure PIE errors: libXinerama and libXext. I solved this by getting the source for these two and building the .a files locally (but apparently no makefile changes were required). Not very sure if these aren't actually part of every standard libx11 install anyway, so maybe they should be dynamic...
      • Other (crystal dependencies?), also via package manager: libevent_pthreads, libevent, and libpcre
      • libgc is currently shipped and linked automatically by Crystal itself so there is no need for it
    • Stays dynamically linked:
      • libgtk-3 and its dependencies, because afaik Gtk is installed everywhere, even on Qt-based distros. If you know of any common distribution that does not include Gtk libs by default please let me know. Gtk does also not officially support static linking. libgtk-3, libgd_pixbuf-2.0, libgio-2.0, libgobject-2.0, libglib-2.0, libgobject-2.0
      • glibc / unproblematic libraries according to this list: libX11, libm, libpthread, librt, libdl.
  10. All in all, once you have libxdo.a, libXext.a and libXinerama.a inside the folder static, the following builds the final binary which should be very portable: shards build -Dpreview_mt --link-flags="-L$PWD/static -Wl,-Bstatic -lxdo -lxkbcommon -lXinerama -lXext -lXtst -lXi -levent_pthreads -levent -lpcre -Wl,-Bdynamic". When not in development, increase optimizations and runtime speed by adding --release. The resulting binary is about 3.6 MiB in size.
  11. Attach the installer with bin/ahk_x11 --compile src/installer.ahk tmp && mv tmp bin/ahk_x11. Explanation: The installer is not shipped separately and instead bundled with the binary by doing this. Bundling is the same thing as compiling a script as a user. As you can see, it is possible to repeatedly compile a binary, with each script being appended at the end each time. Only the last one actually executed - and only if no params are passed to the program. There's no point in compiling multiple times, but it allows us to ship a default script (the installer) for when no arguments are passed. In other words, this is possible for a user: ahk_x11 --compile script1.ahk && ./script1 --compile script2.ahk && ./script2 but no one will ever do that.

AHK_X11의 주요 특징을 정리해보면 아래와 같습니다.

  • Crystal/libxdo/x11-cr/x_do.cr 등을 이용하여 바닥부터 개발
  • 약 80퍼센트 정도의 호환성을 목표. 현재는 60%정도 완성
  • 핫키, 핫스트링, 윈도우 관리, 센드키, 파일 관리, 마우스 제어(클릭만), GUI, 스크립팅 등을 지원

좀 더 자세한 내용은 아래 웹페이지를 참고해보시면 좋을것 같네요...


오늘의 블로그는 여기까지고요..
항상믿고 봐주셔서 감사합니다. 

728x90
300x250