语境
我正在和其他人一起编码 RefPerSys ,C++17 中的 GPLv3+ 项目,位于 gitlab对于 GNU/Linux/x86-64/Debian/Sid。其fltk-branch git branch正在使用 FLTK 1.4 ,从源代码编译,带有 Xorg显示服务器。
我有 C++ 类(在 file headfltk_rps.hh
中):
class RpsGui_Window: public Fl_Double_Window
{
static std::set<RpsGui_Window*> _set_of_gui_windows_;
public:
virtual int handle(int);
protected:
Fl_Menu_Bar *guiwin_menubar;
std::string guiwin_label;
virtual void initialize_menubar(void) =0;
RpsGui_Window(int w, int h, const std::string& lab);
RpsGui_Window(int x, int y, int w, int h, const std::string& lab);
public:
virtual ~RpsGui_Window();
/// .... skipping irrelevant code
const std::string label_str(void) const {
return guiwin_label;
};
}; /// end class RpsGui_Window
class RpsGui_CommandWindow : public RpsGui_Window
{
static constexpr int right_menu_gap = 16;
static constexpr int menu_height = 20;
Fl_Pack* cmdwin_pack;
friend void rps_fltk_initialize(int &,char**);
virtual void initialize_menubar(void);
virtual void initialize_pack(void);
static void menu_dump_cb(Fl_Widget*, void*);
static void menu_exit_cb(Fl_Widget*, void*);
public:
RpsGui_CommandWindow(int w, int h, const std::string& lab);
RpsGui_CommandWindow(int x, int y, int w, int h, const std::string& lab);
virtual ~RpsGui_CommandWindow();
}; // end class RpsGui_CommandWindow
我正在使用输出到
std::cerr
的旧 C++ 宏进行调试(定义在 refpersys.hh
lines 315 及以下)这样的 as below : RPS_DEBUG_LOG(GUI, "RpsGui_CommandWindow::initialize_pack this:"
<< RpsGui_ShowWidget(this)
<< std::endl << "... cmdwin_pack:"
<< RpsGui_ShowWidget(cmdwin_pack));
屏幕上仍然有问题。
见 RefPerSys issue#33有关更多详细信息(带有屏幕截图)。
我想输出给定 FLTK 小部件 w.r.t 的位置。我的 X11 根窗口。 FWIW
xdpyinfo
正在给予(跳过了很多输出)name of display: :0
version number: 11.0
vendor string: The X.Org Foundation
vendor release number: 12008000
X.Org version: 1.20.8
screen #0:
dimensions: 5360x1440 pixels (1418x381 millimeters)
resolution: 96x96 dots per inch
问题
换句话说,我要编码 (用于调试目的)
int RpsGui_Window::x_wrt_root() const;
作为 返回
this
的左上角水平坐标的成员函数w.r.t. X11根窗口但我不确定如何编写代码。调用
XGetWindowAttributes
在功能 fl_handle
FLTK ( file src/Fl_x.cxx
,靠近第 2159 行)可能与我的问题有关, top_window_offset
member function 也是如此的 Fl_Widget
最佳答案
有一个从 Fl_Widget 继承的函数:x()和 x() ;你可以调用那些知道父窗口位置:
class RpsGui_CommandWindow {
void your_func () {
int parent_x = RpsGui_Window::x();
}
};
使用X11,您可以调用XQueryTree获取窗口的根ID,然后调用XGetWindowAttributes知道你想要的值(value)。不过,您需要命令窗口的 X11 窗口 ID。为此在 FLTK docs有一些记录在案的全局变量可以访问该数据。必须在调用 Fl_Window::make_current() 之后完成
我知道这个“命令”窗口是菜单,在图像中它似乎位于正确的位置但宽度错误,或者可能是窗口管理器改变了大小。在这种情况下,您应该有一个事件处理程序来调整小部件的大小。
关于c++ - FLTK 1.4 小部件位置 w.r.t. X11 根窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61931734/