FLTK 1.4 小部件位置 w.r.t。 X11 根 window?

FLTK 1.4 widget position w.r.t. X11 root window?

上下文

我正在和其他人一起编码RefPerSys, a GPLv3+ project in C++17 on gitlab for GNU/Linux/x86-64/Debian/Sid. Its fltk-branch git branch is using FLTK 1.4, compiled from source code, with an 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 and following) such 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 根 window。 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;

作为返回thisw.r.t左上角水平坐标的成员函数。 X11 root window 但我不确定如何编写代码。

FLTK函数fl_handle中对XGetWindowAttributes的调用(file src/Fl_x.cxx, near line 2159) is probably related to my question, and so is the top_window_offset member function of Fl_Widget

有一个函数继承自Fl_Widget:x() and x();你可以打电话给那些知道 parent window 位置的人:

class RpsGui_CommandWindow {
    void your_func () {
        int parent_x = RpsGui_Window::x();
    }
};

对于 X11,您可以调用 XQueryTree to obtain the root ID of the window and then call XGetWindowAttributes to know the value you want. You need the X11 window ID of your command window though. For that In FLTK docs 有一些已记录的全局变量可以访问该数据。必须在调用 Fl_Window::make_current()

之后完成

我知道这个 "command" window 是菜单,在图像中它似乎位于正确的位置但宽度错误或者可能是 window 经理已更改尺寸。在那种情况下,您应该有一个事件处理程序来调整您的小部件的大小。