ユーザーがフォーカスを変更するたびにアクティブなウィンドウ (フォーカスのあるウィンドウ) のタイトルを保存する Windows ユーザー コンポーネント (user32.dll) を使用して、C# .NET WindowsForms アプリケーションを既に開発しました。
Linux で Mono C# を使用して同じことを行う予定です。出来ますか?
はいの場合、私が探しているものは何ですか?
ソースに次のgnome-screenshot
ような機能があるかどうかを確認することにしました (アクティブなウィンドウのスクリーンショットを撮るためだけに):
static GdkWindow *
screenshot_find_active_window (void)
{
GdkWindow *window;
GdkScreen *default_screen;
default_screen = gdk_screen_get_default ();
window = gdk_screen_get_active_window (default_screen);
return window;
}
上記が何も返さない場合、「マウスポインターの下のウィンドウ」にフォールバックするロジックがいくつかあります。
GdkWindow *
do_find_current_window (void)
{
GdkWindow *current_window;
GdkDeviceManager *manager;
GdkDevice *device;
current_window = screenshot_find_active_window ();
manager = gdk_display_get_device_manager (gdk_display_get_default ());
device = gdk_device_manager_get_client_pointer (manager);
/* If there's no active window, we fall back to returning the
* window that the cursor is in.
*/
if (!current_window)
current_window = gdk_device_get_window_at_position (device, NULL, NULL);
if (current_window)
{
if (screenshot_window_is_desktop (current_window))
/* if the current window is the desktop (e.g. nautilus), we
* return NULL, as getting the whole screen makes more sense.
*/
return NULL;
/* Once we have a window, we take the toplevel ancestor. */
current_window = gdk_window_get_toplevel (current_window);
}
return current_window;
}
上記のすべては、私が知る限り、libgdk-pixbuf に排他的に依存しています。それができない場合は、Gdk のソースでこれらの関数の実装をいつでも確認できます。