在Gnome或KDE中以编程方式移动桌面上的应用程序窗口

Move application windows on desktop programmatically in Gnome or KDE

本文关键字:桌面 移动 窗口 应用程序 方式 编程 Gnome KDE      更新时间:2023-10-16

我想使用c++程序重新定位桌面上的应用程序窗口。我该怎么做,我需要两种情况的解决方案。

  1. 当我有了要移动的应用程序的源时。

  2. 通过编写外部程序移动其他应用程序的窗口。

外部Bash脚本:

xdotool   search --onlyvisible --class dolphin   windowmove 13 37
#                                         ^                 ^   ^
#                                   window class            X & Y coordinates

有关此方面的详细信息,请使用xdotool searchxdotool windowmoveman xdotool

C++示例:

#include <cstdlib>
#include <string>
#include <sstream>
using namespace std;
int main()
{
    string cls="dolphin";
    int x=13, y=37;
    stringstream s;
    s<<"xdotool search --onlyvisible --class "<<cls<<" windowmove "<<x<<" "<<y;
    system(s.str().c_str());
    return 0;
}

最简单的例子:

#include <stdlib.h>
int main()
{
    system("xdotool search --onlyvisible --class dolphin windowmove 13 37");
    return 0;
}