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

喜你入骨 提交于 2021-01-28 01:52:00

问题


context

I am coding with others 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 display server.

I have C++ classes like (in 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

and I am debugging with old C++ macros outputting to std::cerr (defined in 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));

Something is still wrong on the screen. See RefPerSys issue#33 for even more details (with a screenshot).

I would like to output the position of a given FLTK widget w.r.t. my X11 root window. FWIW xdpyinfo is giving (with a lot of output skipped)

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

question

In other words, I want to code (for debugging purposes)

int RpsGui_Window::x_wrt_root() const;

as a member function returning the top left corner horizontal coordinate of this w.r.t. X11 root window but I am not sure to know how to code that.

The call to XGetWindowAttributes in function fl_handle of FLTK (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


回答1:


There is a function inherited from Fl_Widget: x() and x(); you may call those to know the parent window position:

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

With X11, you may call 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 there is some documented global variables to access that data. It must be done after calling Fl_Window::make_current()

I understand that this "command" window is the menu, which in the image it seems positioned in the right position but with wrong width or may be the window manager has changed the size. In that case you should have an event handler to resize your widgets.



来源:https://stackoverflow.com/questions/61931734/fltk-1-4-widget-position-w-r-t-x11-root-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!