Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 08 01:07
    rpglover64 commented #369
  • Aug 07 09:27

    garetxe on master

    Update version of Ubuntu for gi… (compare)

  • Aug 07 09:26

    garetxe on master

    Turn cabal.project into a symli… (compare)

  • Aug 07 09:10
    garetxe commented #387
  • Aug 07 09:01

    garetxe on master

    Turn cabal.project into a symli… (compare)

  • Aug 07 09:00

    garetxe on master

    Add Freetype2 bindings, require… Add bindings for GStreamer Edit… (compare)

  • Aug 07 05:15

    garetxe on master

    Add support for GValue elements… (compare)

  • Aug 07 00:15
    TheMBL09898 commented #387
  • Aug 03 03:37
    juhp commented #387
  • Aug 03 03:37
    juhp commented #387
  • Aug 02 08:01
    garetxe commented #387
  • Aug 01 13:56
    juhp edited #387
  • Aug 01 13:34
    juhp opened #387
  • Jul 17 00:07
    mpilgrem commented #384
  • Jul 10 06:58
    garetxe commented #386
  • Jul 10 06:58
    garetxe closed #385
  • Jul 10 06:58
    garetxe commented #385
  • Jul 10 00:52
    lyiriyah closed #386
  • Jul 10 00:52
    lyiriyah commented #386
  • Jul 09 22:23
    Seppli11 commented #385
Miguel Negrão
@miguel-negrao
This is happening in the context of code, where I'm trying to have a more declarative approach to adding and removing widgets to a container. I use HList since widgets can have different types. The "map" type functions for hlist are these:
data HPackBox = HPackBox
instance (IsDescendantOf Box a, IsDescendantOf Widget b,
    Constructible b tag, MonadIO m, GObject a, GObject b,
    input ~ ((a, Bool, Bool, Word32), (ManagedPtr b -> b, [AttrOp b tag])), output ~ m b) =>
    ApplyAB HPackBox input output where
        applyAB _ ((box, expand, fill, padding), (ctr, attrs)) = do
            widget <- new ctr attrs
            boxPackStart box widget expand fill padding
            return widget

data HDestroyWidget = HDestroyWidget
instance (IsWidget o) => ApplyAB HDestroyWidget o (IO ()) where
    applyAB _ widget = widgetDestroy widget
Then I pass in the list of widgets to add:
(Button, [#label := ("Hello World 1"::Text)]) .*.
(Button, [#label := ("Hello World 1"::Text)]) .*.
(Button, [#label := ("Hello World 1"::Text)]) .*.
(Button, [#label := ("Hello World 1"::Text)]) .*.
(Switch, [])  .*. -- crashes ?
(Scale, [])  .*.
HNil)
So in order to have this interface be universal I would need to be able to properly construct any widget with new. So my question is if every newX method can be replicated with new and attributes.
Miguel Negrão
@miguel-negrao
Regarding using widgetDestroyI just need to remove the widget from the container, I can't find the source but I read somewhere that widgetDestroy is ok to remove from a container. I will try with containerRemove.
And also, thanks a lot for the help !!!
Miguel Negrão
@miguel-negrao
containerRemove doesn't cause the crash.
Iñaki
@garetxe

So my question is if every newX method can be replicated with new and attributes.

Ah, I see, thanks for the explanation. (Cool approach!) I hesitate to say that all widgets can be created in this way (I cannot think of an exception now, but I'm not sure), but this certainly seems to be the direction of travel.

containerRemove doesn't cause the crash.

Yes, this is definitely safer. By doing this you are telling the container to drop its reference to the widget, but you are not invalidating it, so the widget is not becoming invalid "behind Haskell's back", so to speak

Miguel Negrão
@miguel-negrao

So my question is if every newX method can be replicated with new and attributes.

Ah, I see, thanks for the explanation. (Cool approach!) I hesitate to say that all widgets can be created in this way (I cannot think of an exception now, but I'm not sure), but this certainly seems to be the direction of travel.

I tried the following and it worked !

    adjustment <- new Adjustment [#value := 0.0, #lower := 0.0, #upper := 51, #stepIncrement := 0.1, #pageIncrement := 1.0, #pageSize := 1.0]
    scale <- new Scale [ #orientation := OrientationVertical, #adjustment := adjustment]

So that means that every "xNew" method has corresponding attributes that are generated automatically with the same name as the name given to the function "xNew"'s arguments in the documentation ?

Iñaki
@garetxe

I tried the following and it worked !

Great :)

So that means that every "xNew" method has corresponding attributes that are generated automatically with the same name as the name given to the function "xNew"'s arguments in the documentation ?

It is not automatic, unfortunately, the writer of the C code has to make sure that the relevant arguments are exposes as GObject properties. But in practice, in Gtk at least, it seems to almost always be the case, and all the different constructors are just convenience wrappers over g_object_new, setting the properties. Something like what you see in gtk_button_new_with_label.

This is equivalent to calling new with attributes in haskell-gi.
tripa
@tripa:matrix.org
[m]
Ha ha I came with a similar question about new equivalence
I was missing gtk_message_dialog_new from the bindings, hacked around with a few properties in the generic new list and a separate #setTransientFor (that took me the longest to identify)
And I was wondering if it would give the same results
(…and that actually doesn't need to be separate, it just was because it took so long to pin down)
Iñaki
@garetxe
Yes, that should do it. If you want to check what gtk_message_dialog_new is doing internally, you can check here.
(The reason that gtk_message_dialog_new is not in the bindings is because it accepts a variable number of arguments, and we don't bind such functions.)
tripa
@tripa:matrix.org
[m]
Yes, source diving was how it ended for me (and how I identified the final setTransientFor)
Good to know for the missing binding, I was wondering
Perhaps a stub could be generated in Haddock to explain? I tried looking around for an explanation, but it's hard to know where to look
Iñaki
@garetxe
Good suggestion, thanks! Could you please file an issue so I don't forget about this? I was planning to do some work on the documentation generator (the gtk-doc format seems to have changed, so the haddocks don't look great right now), this might be a good chance.
If you have some ideas about the language please feel free to suggest them in the issue, I am not sure what the right approach is here.
tripa
@tripa:matrix.org
[m]
Will do!
Iñaki
@garetxe
Great, thanks!
tripa
@tripa:matrix.org
[m]
GObject.objectGetData documentation says it returns “the data if found, or Nothing if no such data exists”
But its signature is * -> MonadIO m => m (Ptr ())
After much head-scratching, I'm guessing it really returns nullPtr if no data exists?
Iñaki
@garetxe
@tripa:matrix.org Yes, that's right! The gtk-doc -> haddock translator uses a number of heuristics to improve the Haskell side docs, one of which is replacing NULL by Nothing. This is almost always the right thing to do, since nullable arguments on the C side are mapped to Maybe arguments. But this is indeed wrong for objectGetData.
eldritch cookie
@dark-ether
how do i get started? i tried to follow the gtk4 guide but there isn't a function called applicationRun
Iñaki
@garetxe
@dark-ether There is an example of how to set up a gtk4 application at https://github.com/haskell-gi/haskell-gi/tree/master/examples/Gtk4
Iñaki
@garetxe
You'll need ghc version 9.2.1 or newer to compile the adwaita example. If you don't want to or cannot use that version, remove the OverloadedRecordDot extension and change all method calls of the form obj.method to #method obj
eldritch cookie
@dark-ether
what does a expression like [#transitionType := Gtk.StackTransitionTypeUnderUp]
mean ? i tried searching but it still is unclear to me
eldritch cookie
@dark-ether
also things like new Gtk.Box [#orientation := Gtk.OrientationHorizontal] how is new defined? is it a function? if so why isn't it prefixed with something?
Iñaki
@garetxe

what does a expression like [#transitionType := Gtk.StackTransitionTypeUnderUp]
mean ? i tried searching but it still is unclear to me

It means setting the transitionType property of the object to the value Gtk.StackTransitionTypeUnderUp.

You can see what this attribute does in the documentation for GtkStack: https://hackage.haskell.org/package/gi-gtk-4.0.5/docs/GI-Gtk-Objects-Stack.html#g:attr:transitionType
Alternatively, you can query what the type system is doing by using resolveAttr, for example by doing the following inside cabal repl for your project:
:set -XTypeApplications 
:set -XOverloadedLabels
import qualified GI.Gtk as Gtk
import Data.GI.Base.Attributes (resolveAttr)
resolveAttr (undefined :: Gtk.Stack) #transitionType
If you do this in a modern terminal you will get a clickable link pointing to the documentation

also things like new Gtk.Box [#orientation := Gtk.OrientationHorizontal] how is new defined? is it a function? if so why isn't it prefixed with something?

new comes from Data.GI.Base: https://hackage.haskell.org/package/haskell-gi-base/docs/Data-GI-Base.html#v:new

eldritch cookie
@dark-ether
wow, thanks for the help.
Timothy Copeland
@tacopeland
Has anyone ever got GTK.widgetShapeCombineRegion or GDK.windowShapeCombineRegion to work? I've tried this, but it doesn't actually change the region:
    setSourceRGBA 0.0 0.0 0.0 0.0
    withTargetSurface $ \surface -> do
      liftIO $ withSurface surface $ \ptr -> do
         newPtr <- return (castPtr ptr) :: IO (Ptr Cairo.Surface)
         surf <- newManagedPtr newPtr (return ())
         region <- Gdk.cairoRegionCreateFromSurface (Cairo.Surface surf)
         Gtk.widgetShapeCombineRegion widget (Just region)
seppli
@seppli:matrix.org
[m]
When I try to build a project which uses gi-harfbuzz, I get the following error. Does anybody know how to solve it?
GI/HarfBuzz/Functions.hs:1772:1: error:
    Could not find module ‘GI.Freetype2.Structs.Face’
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
     |
1772 | import qualified GI.Freetype2.Structs.Face as Freetype2.Face
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cabal: Failed to build gi-harfbuzz-0.0.5 (which is required by
CookieCalculator-0.1.0.0). See the build log above for details.
eldritch cookie
@dark-ether
how do i use a builder it returns a object do i need to know the type previously and use toclass like toButton?