目錄
前言
1 開始後weston client端服務啟動
2 自定義按鍵截屏
3 實作分析
總結
前言
weston架構下,可以通過标準鍵盤的:WIN+s 實作截屏,但是如果我們要用自己的按鍵實作截屏又該如何操作呢?
1 開始後weston client端服務啟動
weston會在啟動時或按需起一些子程序,它們本質上是Weston的client,它們會通過專用的協定做一些系統應用的工作。如系統應用weston-desktop-shell負責一些系統全局的界面,比如panel, background, cursor, app launcher, lock screen等。它不作為weston服務本身的一部分,而是作為一個client。weston-keyboard是軟鍵盤面闆。weston-screenshooter和weston-screensaver分别用于截屏和屏保,它們都是按需才由Weston啟動的。前者在截屏快捷鍵按下時啟動,後者在需要鎖屏時啟動。
上圖總結而言為:
1、weston-desktop-shell負責一些系統全局的界面,比如panel, background, cursor,
app launcher, lock screen等。
2、weston-keyboard是軟鍵盤面闆。
3、weston-screenshooter和weston-screensaver分别用于截屏和屏保,它們都是按
需才由Weston啟動的。
2 自定義按鍵截屏
在筆者調試的嵌入式裝置中, weston-screenshooter可執行程式的位置在:/usr/libexec。
weston-screenshooter的初始化位置應該是從應用層啟動的,是以在weston/desktop-shell/shell.c中
wet_shell_init
screenshooter_create
screenshooter_create中的内容為:
weston_compositor_add_key_binding(ec, KEY_S, MODIFIER_SUPER,
screenshooter_binding, shooter);//截屏由win+S鍵觸發
weston_compositor_add_key_binding(ec, KEY_R, MODIFIER_SUPER,
recorder_binding, shooter);//錄屏由win+R鍵觸發
是以在此處添加自己的截屏處理按鍵綁定shooter即可,如:
weston_compositor_add_key_binding(ec, KEY_W, 0,
screenshooter_binding, shooter);//截屏由W鍵觸發
3 實作分析
weston_compositor_add_key_binding的内容為:
static void
screenshooter_binding(struct weston_keyboard *keyboard, uint32_t time,
uint32_t key, void *data)
{
struct screenshooter *shooter = data;
char *screenshooter_exe;
int ret;
ret = asprintf(&screenshooter_exe, "%s/%s",
weston_config_get_libexec_dir(),
"/weston-screenshooter");
if (ret < 0) {
weston_log("Could not construct screenshooter path.\n");
return;
}
if (!shooter->client)
shooter->client = weston_client_launch(shooter->ec,
&shooter->process,
screenshooter_exe, screenshooter_sigchld);
free(screenshooter_exe);
}
上述代碼中screenshooter_exe為weston-screenshooter可執行檔案的具體位置,weston_client_launch實作了screenshooter_exe的啟動。具體實作為weston_client_launch中設定了一個fork程序,執行
child_client_exec(sv[1], path);
其中path即為weston-screenshooter可執行檔案的位置。
總結
上述分析的可以通過下圖進行表述