gpt4 book ai didi

window - 将属于我启动的独立进程的 X11 窗口嵌入到我自己的窗口中?

转载 作者:行者123 更新时间:2023-12-05 03:14:11 26 4
gpt4 key购买 nike

有没有简单的方法来做到这一点?我从来没有在任何地方看到过这个(除了 Adob​​e/... Firefox 的插件),所以我对此表示怀疑...

如果没有,是否有可靠的、hacky 的方法(例如通过 LD_PRELOAD 挂接到该进程的 Xlib 调用)?

如果重要的话,假设国外进程是mplayer,我的编程语言是C。我有一种直觉,直接使用 Xlib 是我最好的选择,但请随时提出其他选择。仅 mplayer 的解决方案是不够的。

最佳答案

如果你know window id您想要嵌入的窗口,您可以将它重新定位到您的窗口(使用 XReparentWindow ),即使它是由另一个进程创建的。

对于 mplayer,有“-wid”命令行选项。如果您将窗口 ID 传递给它,mplayer 会自动创建它的窗口作为 wid 的子窗口:

−wid (also see −gui-wid) (X11, OpenGL and DirectX only)

This tells MPlayer to attach to an existing window. Useful to embed MPlayer in a browser (e.g. the plugger extension). This option fills the given window completely, thus aspect scaling, panscan, etc are no longer handled by MPlayer but must be managed by the application that created the window.

你可以通过传递'-slave'标志并发送commands来控制mplayer到标准输入(或 fifo)

使用 node-x11 嵌入 mplayer 的示例:

var x11 = require('x11');
var spawn = require('child_process').spawn;
x11.createClient(function(err, display) {
var X = display.client;
var wid = X.AllocID();
X.CreateWindow(wid, display.screen[0].root, 100, 100, 400, 300, 0, 0, 0, 0, {eventMask: x11.eventMask.SubstructureNotify|x11.eventMask.StructureNotify});
X.MapWindow(wid);
var mplayer = spawn('mplayer', ['-wid', wid, './video.mp4']);

function pause() {
mplayer.stdin.write('pause\n');
setTimeout(play, 1000);
}

function play() {
mplayer.stdin.write('play\n');
setTimeout(pause, 1000);
}

pause();


var mpid;
X.on('event', function(ev) {
console.log(ev);
if (ev.name == 'CreateNotify')
mpid = ev.wid;
if (ev.name == 'ConfigureNotify' && ev.wid == wid) {
X.ResizeWindow(mpid, ev.width, ev.height);
}

});
});

关于window - 将属于我启动的独立进程的 X11 窗口嵌入到我自己的窗口中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26335469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com