Recent

Author Topic: How to get the x11 XID handle of TCustomControl equvalent to HWND on windows  (Read 6840 times)

sainimu78

  • Full Member
  • ***
  • Posts: 117
scn:TCustomControl;

The scn.Handle will retrurn a PGtkWidget.

Code: Pascal  [Select][+][-]
  1. procedure TMyPanel.Paint;
  2. var
  3.   pW:PGtkWidget;
  4.   pDW:PGDKWindow;
  5.   w, h:Integer;
  6.   attrs:TXWindowAttributes;
  7. begin
  8.   pW := PGtkWidget(Handle);
  9.   pDW := pW^.window;// gtk_widget_get_window(pW);
  10.   if(pDW = nil)then
  11.     Exit;
  12.   if(fGC <> nil)then
  13.     Exit;
  14.   fWindow := gdk_x11_drawable_get_xid(pDW);
  15.   fDisplay := gdk_x11_drawable_get_xdisplay(pDW);
  16.   //if(fGC <> nil)then
  17.   //  XFreeGC(fDisplay, fGC);
  18.   fGC := XCreateGC(fDisplay, fWindow, 0, nil);
  19.   XGetWindowAttributes(fDisplay, fWindow, @attrs);
  20.  
  21.   w := attrs.width;
  22.   h := attrs.height;
  23. end;
The w and h seems wrong, it is the w and h of the whole form, how to get the correct fWindow with lclgtk2 ?
Is pDW here equvalent to HWND on windows ? I can do custom paint a TCustomControl using windows native api on windows, I think I just get a wrong pDW and I don't know how to.

benohb

  • Full Member
  • ***
  • Posts: 213
Code: Pascal  [Select][+][-]
  1. fWindow := GDK_WINDOW_XWINDOW(PGtkWidget(PtrUInt(Handle))^.window);


Curiosity killed me :) . what do you want to do ??

sainimu78

  • Full Member
  • ***
  • Posts: 117
Code: Pascal  [Select][+][-]
  1. fWindow := GDK_WINDOW_XWINDOW(PGtkWidget(PtrUInt(Handle))^.window);


Curiosity killed me :) . what do you want to do ??
This is still not good still gets a wrong w & h.
I want to paint using a third party library, it creates a render context on TCustomControl, I need to pass a correct fWindow to it.

benohb

  • Full Member
  • ***
  • Posts: 213
I can not help you without understanding..

what is "The third party library" ??? cario ??


emailadd

  • Newbie
  • Posts: 3
Hi all,

I have a similar issue like this. I want to draw on TPanel using SDL (v1.2) library. In order to have SDL to draw on the component, I need to pass the X11 window ID using 'SDL_WINDOWID' environment.

fWindow := GDK_WINDOW_XWINDOW(PGtkWidget(PtrUInt(Panel1.Handle))^.window);

Using the function above, I was able to get the X window ID and passed into SDL. However, it draws not on the component, but on the form.
Any suggestions to fix this?

I am using Lazarus v1.0.10 under Ubuntu 14.04-LTM

Regards,


 
« Last Edit: August 29, 2018, 01:01:57 am by emailadd »

 

TinyPortal © 2005-2018