Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 20 14:15
    Abastro edited #383
  • May 20 14:15
    Abastro edited #383
  • May 20 14:15
    Abastro opened #383
  • Apr 28 06:12
    psiska commented #367
  • Apr 06 02:00
    donaldcallen closed #382
  • Apr 06 02:00
    donaldcallen commented #382
  • Apr 05 06:21
    garetxe commented #382
  • Apr 05 06:20
    garetxe commented #382
  • Apr 04 18:31
    donaldcallen opened #382
  • Mar 25 14:41
    garetxe commented #381
  • Mar 25 10:07
    peter-jerry-ye closed #381
  • Mar 25 10:07
    peter-jerry-ye commented #381
  • Mar 25 09:48
    peter-jerry-ye opened #381
  • Mar 24 08:31
    garetxe opened #380
  • Mar 20 08:59
    spinus synchronize #379
  • Mar 20 05:36
    spinus opened #379
  • Feb 08 17:40
    miguel-negrao edited #378
  • Feb 08 17:37
    miguel-negrao opened #378
  • Feb 08 03:09
    tclfs closed #377
  • Feb 08 03:09
    tclfs commented #377
sheaf
@sheaf:matrix.org
[m]
do
  window <- Gtk.windowNew
  Gtk.onWidgetDestroy window Gtk.mainQuit
Las
@Las:matrix.org
[m]
Thanks
Also: I'm trying out the WebKit example, and the text is much smaller than compared to other browsers
Is it supposed to be like this? Is it perhaps because of NixOS?
Iñaki
@garetxe
Hi @Las:matrix.org !
I also see the text slightly small here. It is not intentional, it seems to be due to defaults in webkit. You can check by opening "Epiphany", Gnome's web browser, which is also based on WebKit.
At least in my computer both epiphany and the webkit example display text at the same size.
If you figure out how to make the default a bit larger I would gladly welcome a pull request :)
Las
@Las:matrix.org
[m]
@garetxe: Thanks for confirming my suspicion, Epiphany shows much larger text (that is within the normal range, albeit a bit smaller than what Firefox displays). What I get on https://haskell.org is text so small that it's hard to even read. It's likely a problem with my nix derivation for it then.
Tisoxin
@vherrmann:shmerver.de
[m]
Hi! I'm currently trying to combine some concepts of gi-gtk-declarative with the reflex-gi-gtk library, but i've hit a (seeming) dead end for me.
But even though gtk-declarative is able to use new (from GI.Gtk) without specifying the bins type, i don't seem to be able to
I can't even write a top-level myNew = new (with GI.Gtk in scope)
1 reply
Tisoxin
@vherrmann:shmerver.de
[m]
Help would be greatly appreciated!
    • Overlapping instances for GI.Constructible a0 tag0
        arising from a use of ‘GI.new’
      Matching instances:
        instance [overlappable] (GI.GObject a, tag ~ 'GI.AttrConstruct) =>
                                GI.Constructible a tag
          -- Defined in ‘Data.GI.Base.Constructible’
        instance (tag ~ 'GI.AttrSet) =>
                 GI.Constructible G.AccelGroupEntry tag
          -- Defined in ‘GI.Gtk.Structs.AccelGroupEntry’
        instance (tag ~ 'GI.AttrSet) => GI.Constructible G.AccelKey tag
          -- Defined in ‘GI.Gtk.Structs.AccelKey’
        ...plus 35 others
        ...plus 95 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
      (The choice depends on the instantiation of ‘a0, tag0’
       To pick the first instance above, use IncoherentInstances
       when compiling the other instance declarations)
    • In the expression: GI.new
      In an equation for ‘myNew’: myNew = GI.new
   |
97 | myNew = G.new
   |         ^^^^^
in this case GI is Data.GI.Base.ShortPrelude and G is GI.GTK
Tisoxin
@vherrmann:shmerver.de
[m]
nvm, i haven't yet found a real solution, but i think i'm able to figure it out myself
Tisoxin
@vherrmann:shmerver.de
[m]
:]
Iñaki
@garetxe
@vherrmann:shmerver.de Great, glad to hear that you figured it out! (And sorry for the slow reply, I have been very busy the last few days)
Please don't hesitate to ask if you run into other issues, I'll try to keep a closer eye on this
Iñaki
@garetxe
(Implementing a reflex-type binding on top of gi-gtk sounds very interesting, by the way! Looking forward to the result.)
Iñaki
@garetxe
Hi! No, in general there is no need to worry about unref'ing memory manually for any type with a GObject or GBoxed instance, the bindings will take care of freeing the memory when the Haskell object gets garbage collected.
Miguel Negrão
@miguel-negrao
@garetxe Thanks ! That makes it quite a bit easier to use than the C api.
Miguel Negrão
@miguel-negrao
I'm getting a SIGSEGV with gi-gtk. The backtrace is at https://gist.github.com/miguel-negrao/ba7990d368bd7c886ecd2fdef2ef5842
To check that I'm not doing anything obviously wrong, I'm creating a widget with new and adding it to a container with boxPackStart box widget expand fill padding
I'm then destroying the widget with widgetDestroy which appears to trigger the crash.
Miguel Negrão
@miguel-negrao
The issue only happens with Switch
Iñaki
@garetxe

I'm then destroying the widget with widgetDestroy which appears to trigger the crash.

This sounds a bit like you are double freeing. Is it necessary to call widgetDestroy in your code? Every widget in Gtk is reference counted. In particular if you create a widget and add it to a box then it will have a refcount of 2: Haskell keeps one (which it will drop once the Haskell object is garbage collected) and the container keeps another.

So basically you never need to care about freeing things manually.

(By the way, when debugging crashes it is useful to run with the following environment vars set:

export G_SLICE="debug-blocks"
export MALLOC_CHECK_=2
export MALLOC_PERTURB_=$(($RANDOM % 255 + 1))
export HASKELL_GI_DEBUG_MEM=1

)

Iñaki
@garetxe

And another question: how would I replicate https://hackage.haskell.org/package/gi-gtk-4.0.5/docs/GI-Gtk-Objects-Scale.html#v:scaleNew with https://hackage.haskell.org/package/haskell-gi-base-0.26.0/docs/Data-GI-Base-Constructible.html#v:new , since it has some additional parameters ?

In general it should be perfectly fine to call scaleNew, but in this case it might be possible to make it work with new too. Have you tried setting the orientation and adjustment attributes? Something like

scale <- new Gtk.Scale [#orientation := ..., #adjustment := ...]
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.