FLTK 1.4小部件位置X11根窗口? [英] FLTK 1.4 widget position w.r.t. X11 root window?

查看:100
本文介绍了FLTK 1.4小部件位置X11根窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文

我正在与其他人进行 RefPerSys 进行编码,这是C ++ 17中在 fltk-branch git分支是使用从源代码编译的 FLTK 1.4 ,其中<一个href ="https://en.wikipedia.org/wiki/X.Org_Server" rel ="nofollow noreferrer"> Xorg 显示服务器.

我有C ++类,例如(在文件headfltk_rps.hh ):

  RpsGui_Window类:公共Fl_Double_Window{静态std :: set< RpsGui_Window *>_set_of_gui_windows_;上市:虚拟int句柄(int);受保护的:Fl_Menu_Bar * guiwin_menubar;std :: string guiwin_label;虚拟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);上市:虚拟〜RpsGui_Window();///....跳过无关的代码const std :: string label_str(void)const {返回guiwin_label;};};///结束类RpsGui_WindowRpsGui_CommandWindow类:公共RpsGui_Window{静态constexpr int right_menu_gap = 16;静态constexpr int menu_height = 20;Fl_Pack * cmdwin_pack;朋友void rps_fltk_initialize(int&,char **);虚拟void initialize_menubar(void);虚拟void initialize_pack(void);静态void menu_dump_cb(Fl_Widget *,void *);静态void menu_exit_cb(Fl_Widget *,void *);上市:RpsGui_CommandWindow(int w,int h,const std :: string& lab);RpsGui_CommandWindow(int x,int y,int w,int h,const std :: string& lab);虚拟〜RpsGui_CommandWindow();};//结束类RpsGui_CommandWindow 

并且我正在调试将旧的C ++宏输出到 std :: cerr (在

屏幕上仍然有错误.有关更多详细信息,请参见 RefPerSys问题#33 ./p>

我想输出给定的FLTK小部件的位置.我的X11根窗口.FWIW xdpyinfo 正在给出(跳过了很多输出)

 显示名称:: 0版本号:11.0供应商字符串:X.Org Foundation供应商发布编号:12008000X.Org版本:1.20.8屏幕#0:尺寸:5360x1440像素(1418x381毫米)分辨率:每英寸96x96点 

问题

换句话说,我要编码(出于调试目的)

  int RpsGui_Window :: x_wrt_root()const; 

作为成员函数,返回此 this w.r.t.的左上角水平坐标.X11根窗口,但我不确定如何编写代码.

在FLTK(解决方案

从Fl_Widget继承了一个函数: x() x();您可以打电话给他们以了解父窗口的位置:

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

使用X11,您可以调用 XQueryTree 以获得窗口的根ID,然后调用 XGetWindowAttributes 知道您想要的价值.但是,您需要命令窗口的X11窗口ID.为此,在FLTK docs 中,有一些已记录的全局变量可以访问该变量数据.必须在调用Fl_Window :: make_current()

之后完成

我知道此命令"窗口是菜单,它在图像中似乎位于正确的位置,但宽度错误,或者可能是窗口管理器已更改大小.在这种情况下,您应该有一个事件处理程序来调整小部件的大小.

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

解决方案

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.

这篇关于FLTK 1.4小部件位置X11根窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆