Closed aeosynth closed 8 years ago
You should never need to use Lib
directly, I consider each time you have to a missing feature in the generator.
With d9fa233809fa5fe1fa14946b8362cc32f889e4d8 it now generates wrappers for struct attributes and a constructor for for them. So now it should be:
window = Gdk::Window.new(nil,
Gdk::WindowAttr.new(title: "Hello World"),
Gdk::WindowAttributesType.flags(TITLE)
)
However it doesn't work for me
(process:28243): Gdk-CRITICAL **: gdk_screen_get_root_window: assertion 'GDK_IS_SCREEN (screen)' failed
(process:28243): Gdk-CRITICAL **: gdk_window_new: assertion 'GDK_IS_WINDOW (parent)' failed
So https://github.com/GNOME/gtk/blob/master/gdk/gdkwindow.c#L1298 fails for me for some reason. Is it because I'm on wayland?
c code will fail similarly; you have to call gdk's init
to fix those errors, and set the window_type
attribute to actually display the window
i get this error now when setting an attribute:
require "gobject/gdk"
attr = Gdk::WindowAttr.new
attr.window_type = Gdk::WindowType::TOPLEVEL
$ crystal gdk.cr
Error in ./gdk.cr:4: instantiating 'Gdk::WindowAttr#window_type=(LibGdk::WindowType)'
attr.window_type = Gdk::WindowType::TOPLEVEL
^~~~~~~~~~~
in ./libs/gobject/generated/gdk/window_attr.cr:102: undefined method 'window_type=' for Nil
to_unsafe.value.window_type = value
^~~~~~~~~~~
================================================================================
Nil trace:
/usr/lib/crystal/primitives.cr:169
def value : T
The following compiles now and has a zero exit code for me:
Gdk.init
window = Gdk::Window.new(nil,
Gdk::WindowAttr.new(title: "Hello World", window_type: Gdk::WindowType::TOPLEVEL),
Gdk::WindowAttributesType.flags(TITLE)
)
A sample that actually shows something on the screen would be welcome :)
require "gobject/gdk"
Gdk.init
attr = Gdk::WindowAttr.new(
width: 800,
height: 600,
window_type: Gdk::WindowType::TOPLEVEL
)
mask = Gdk::WindowAttributesType::ZERO_NONE
win = Gdk::Window.new nil, attr, mask
win.show
LibGLib.main_loop_run LibGLib.main_loop_new nil, true
GLib::MainLoop.new
has a type mismatch - https://github.com/jhass/crystal-gobject/blob/master/src/generated/g_lib/main_loop.cr#L6:
ptr = Pointer(UInt8).malloc(0, 0)
Thanks, I added https://github.com/jhass/crystal-gobject/blob/master/samples/gdk_window.cr For me it just generates an invisible window, if there's something easy to draw something on to it that would be nice, but that's better than nothing I guess :)
i use a tiling wm, so i didn't notice that. i'm using cairo to draw an image, but i need to create a binding for cairo_paint
, so not very easy.
btw, is there a reason you use flags(TITLE)
in Gdk::WindowAttributesType.flags(TITLE)
, instead of ::TITLE
?
No strong one, just to hint the macro, since in a real usecase you likely want to set more of the optional attributes, and Gdk::WindowAttributesType.flags(TITLE, X, Y)
is a lot less verbose than Gdk::WindowAttributesType::TITLE|Gdk::WindowAttributesType::X|Gdk::WindowAttributesType::Y
.
makes sense. thanks for fixing all these issues!
Thanks for reporting!
i'm not clear on when to use
LibGdk
vsGdk
edit: it looks like we're supposed to do this?: