Live data from Hacker News

GUI development with Rust and GTK 4

gtk-rs.org

161–170 of 172 posts

Re: GUI development with Rust and GTK 4

#161

Earlier quoted context omitted.

You’re viewing things from the wrong angle. To begin with, the onus of all of these things has been shifted to the app developer . Previously, a lot of it was up to the user or the desktop environment. I said “ basically force” because non-overlay scrollbars are possible, but getting them requires every app’s developer to change the property everywhere. If (I recall correctly, it’s not even a theme thing.) That’s com…

>You’re viewing things from the wrong angle. Nope, the onus is always on the app developer. Even Microsoft is inconsistent with their own Windows apps using overlay scrollbars. Old Windows apps don't have them, but the new app guidelines for Windows 11 actually say you should use overlay scrolling: https://learn.microsoft.com/en-us/windows/apps/design/contro... Windows developers just have to pick which guidelines th…

Certainly some user preferences could damage some apps. But it mostly didn’t, it was generally good enough, and when it did it commonly pointed to a bug in the app anyway (e.g. setting text foreground colour when you don’t know what the background colour is—you must always set (or know the value of) either neither or both). And this flexibility was used by a variety of platforms.

Since you mention overlay scrollbars again, I’ll emphasise something I only alluded vaguely to in my initial wording: GTK does GNOME-style overlay scrollbars. The look and feel are both completely different from Windows 10 and 11 overlay scrollbars, and you certainly can’t accurately emulate the behaviour and I doubt you can emulate the look either. I’ll also mention something that apparently didn’t make it into my previous comment: macOS lets you turn overlay scrollbars on or off at the user level.

As for getting involved: they’ve been actively and deliberately gutting stuff useful for other platforms, and refusing to undelete things because of their vision of how things should be, seen most clearly in how they’ve handled overlay scrollbars and theming. I’m not interested in getting involved with a project like that; it seems to me fairly clearly a lost cause for anything I could do, if I was even willing to spend that kind of time on such a thing.

Re: GUI development with Rust and GTK 4

#162

Earlier quoted context omitted.

> Custom key themes were removed because the whole concept of them was broken. The concept was never broken on macOS. It's also implemented in a brilliantly simple and very user-accessible way, and requires very little consideration from the application developer. Between that, or having a single configuration file where one can achieve a similar result, deciding which method is better probably boils down to personal…

>The concept was never broken on macOS Yes it is, MacOS also doesn't have key themes. I can't reconfigure a Mac to use Windows keyboard shortcuts. Those are just the default key bindings every Mac app has to support. That's why it works on Mac and it doesn't work on Windows or Linux or anywhere else where the defaults are different. You're comparing apples to oranges here. To elaborate, Mac gets away with it because…

> I can't reconfigure a Mac to use Windows keyboard shortcuts.

Yes you absolutely can. I've tried it and you can rebind copy/paste/undo/etc globally to use Ctrl-c/Ctrl-v/Ctrl-z/etc, using the builtin Settings.app. It takes about a minute or two, a bit more if you want to change everything as you have to rebind them one by one by hunting down the command names in the menus. You can rebind anything for all apps, or only for a specific app. You can also swap Cmd and Opt. This is probably easier for newbies than editing a text file, but you can't trivially check it into git. I still have a PowerPC Mac with OSX 10.5, I should probably check if it was supported at the time, but my hunch is that it was. The point is it's there, out of the box, and it's working extremely well.

The most interesting thing with this setup is what the terminal does: Ctrl-c copies the text when something is selected, and sends SIGINT otherwise. You're having and eating your cake on so many levels.

> The Win or Super key on PC keyboards is historically not used often as a modifier.

Yes and no. The scan code is the same as Cmd. If you plug an Apple keyboard to a PC or a PC keyboard to a Mac, the only issue is figuring out if you want to swap it with Alt/Opt.

Cmd/Win has also always been a very popular choice for the "modifier" key in minimalistic/tiling window managers, and GNOME has supported that too, even back in the early 2.x days (I'm not old enough to remember 1.x). Even Windows started using Win-E for things like launching the file manager, Win-P for configuring the screens, Win-arrow keys for window placement, etc - some of that more than 20 years ago IIRC. So it's not like there's no historical precedent, it's always been about conventions, platform defaults, and what do you want to leave up to the user.

I fully agree with "convention over configuration", but if you take away the "configuration" part, what's left is "my way or the highway".

> The "free" in free desktop means that if you want to change all keybindings for every app to work to your preference, then you get to fork those apps, change the code yourself, recompile and then deal with any of the resulting bugs.

Well, I could argue up until this point, but this is the suckless.org attitude. Awesome. Is this how dwm becomes more user-friendly than GNOME?

FYI I've never had to compile Emacs, Sway, or Alacritty (or ANYTHING on Mac) just to change the key bindings, and I'm definitely the guy who tries to change EVERYTHING.

Re: GUI development with Rust and GTK 4

#163

Earlier quoted context omitted.

Honestly this looks like programming style from 90s. Why not design UIs in an editor that saves layout to XML?

Machine generated XML doesn’t play nice with version control for views that are even moderately complex. Merge conflicts become more of a nightmare to untangle as your app matures, plus it can make pull requests unintelligible. This is part of why for apple platform dev, several years ago I abandoned XML-based XIB and storyboard UI design for any collaborative project. Writing it all out in code (even with just UIKit…

Absolutely. XML is rarely a good solution for any problem, and usually the worst.

> I’d like to do the same for Android projects, but Google is hellbent on the XML usage if you’re building with Android Framework…

For sure the Android API is oriented towards building GUIs in XML, but it's actually quite possible to build your Android GUI in Java code.

When I started developing for Android, I took a look at a few tutorials and said "no way", searched the web for how to build Android GUIs programmatically, and never looked back.

Re: GUI development with Rust and GTK 4

#164
post #9

Rust GTK4 "hello world" app, as a downloadable project, demonstrating the builder pattern: https://github.com/SixArm/rust-guideposts/blob/main/projects...

Honestly this looks like programming style from 90s. Why not design UIs in an editor that saves layout to XML?

XML? That's so ... turn of the century.

Thankfully the industry has mostly woken up from the collective nightmare that was XML.

But apparently a few poor souls are still painfully asleep.

Re: GUI development with Rust and GTK 4

#165

Earlier quoted context omitted.

> Custom key themes were removed because the whole concept of them was broken. The concept was never broken on macOS. It's also implemented in a brilliantly simple and very user-accessible way, and requires very little consideration from the application developer. Between that, or having a single configuration file where one can achieve a similar result, deciding which method is better probably boils down to personal…

I’m now curious whether Emacs key bindings work in GTK text boxes on macOS.

It's inconsistent. I haven't touched my Gtk settings on macOS, and here are the defaults: Ctrl-A in Gimp (Gtk2) selects all text; in Inkscape (Gtk3) it hops to the start of the line; I'm not sure which apps use Gtk4 so can't tell for this one.

Re: GUI development with Rust and GTK 4

#166

Earlier quoted context omitted.

>The concept was never broken on macOS Yes it is, MacOS also doesn't have key themes. I can't reconfigure a Mac to use Windows keyboard shortcuts. Those are just the default key bindings every Mac app has to support. That's why it works on Mac and it doesn't work on Windows or Linux or anywhere else where the defaults are different. You're comparing apples to oranges here. To elaborate, Mac gets away with it because…

> I can't reconfigure a Mac to use Windows keyboard shortcuts. Yes you absolutely can. I've tried it and you can rebind copy/paste/undo/etc globally to use Ctrl-c/Ctrl-v/Ctrl-z/etc, using the builtin Settings.app. It takes about a minute or two, a bit more if you want to change everything as you have to rebind them one by one by hunting down the command names in the menus. You can rebind anything for all apps, or onl…

>Yes you absolutely can. I've tried it and you can rebind copy/paste/undo/etc globally to use Ctrl-c/Ctrl-v/Ctrl-z/etc, using the builtin Settings.app. It takes about a minute or two, a bit more if you want to change everything as you have to rebind them one by one by hunting down the command names in the menus

Sorry I don't count that, this is comparing apples to oranges again. It's still not the same as key themes. You're doing the same thing I was talking about earlier, manually reconfiguring every shortcut in every app and dealing with all the resulting bugs yourself. It doesn't work either if the command has a slightly different name for some reason. Even if you wanted this type of configuration in GNOME, and if it were even possible, which it sort of is already, it still would be implemented in a completely different way than key themes were. Because key themes were just broken.

The difference is key themes are another thing that claims to do it automatically. If they were working correctly there would be no conflicts. They don't though, so either way if there are conflicts you have to hunt those down and reconfigure every app individually again and then you get to remember which apps have different shortcuts because you had to do something weird to resolve the key conflicts. The point is, I can't just flip a switch that changes everything to Windows shortcuts.

The other issue here is how this relates to GTK and GNOME apps. Technically, GTK still has an API to create Mac-style menu bars. GNOME apps don't use that API as a matter of convention because GNOME doesn't have a global menu bar like Mac does. If they did, it would be a lot easier to build that same kind of setting GUI. But they don't. So, as always, it still comes back to how the app developer chooses to make the app and what platform conventions they follow. Please be aware of what you're asking for here, it may seem like a simple request to you but when you dig into it it's really asking to change several things in every app to be more like some other platform. And that's not a reasonable request unless you're willing to see it through all the way.

>Ctrl-c copies the text when something is selected, and sends SIGINT otherwise. You're having and eating your cake on so many levels.

This behaviour is again dependent on how the terminal handles the menu. It could be implemented in a different way where it always interprets it as Copy even when nothing is selected. It won't work at all if you have another key theme where Ctrl-C is an action that's always enabled. And what if I want to rebind SIGINT in this scenario, how does that work? I don't expect terminals to add a menu entry for every terminal escape, but that's how they would have to do it using the Apple approach. Or they have to add their own setting for this, which is no better than before.

>Well, I could argue up until this point, but this is the suckless.org attitude.

No, this is the everything attitude. An app developer can always choose what settings they want to present to the user and what features they want to support. If you don't like it, then yes, most of the time it's "my way or the highway". That's how this software thing works, open source or closed source. Mac, Windows, Linux, all of them have a different collection of settings they support. If it's open source you just always have the extra option to recompile if the original developer didn't want to do it.

Re: GUI development with Rust and GTK 4

#167

Earlier quoted context omitted.

>You’re viewing things from the wrong angle. Nope, the onus is always on the app developer. Even Microsoft is inconsistent with their own Windows apps using overlay scrollbars. Old Windows apps don't have them, but the new app guidelines for Windows 11 actually say you should use overlay scrolling: https://learn.microsoft.com/en-us/windows/apps/design/contro... Windows developers just have to pick which guidelines th…

Certainly some user preferences could damage some apps. But it mostly didn’t, it was generally good enough, and when it did it commonly pointed to a bug in the app anyway (e.g. setting text foreground colour when you don’t know what the background colour is—you must always set (or know the value of) either neither or both). And this flexibility was used by a variety of platforms. Since you mention overlay scrollbars…

>But it mostly didn’t, it was generally good enough, and when it did it commonly pointed to a bug in the app anyway

That hasn't changed though? The individual settings might have changed. Some were added and some were taken away, as is usual in development.

>The look and feel are both completely different from Windows 10 and 11 overlay scrollbars, and you certainly can’t accurately emulate the behaviour and I doubt you can emulate the look either.

If there are subtle things then no you probably can't without writing a new widget. So again, you're talking about having a big #ifdef inside the scrollbar code. Practically speaking the maintainers would then have to maintain at least two separate scrollbar implementations. Those are the Windows 11 scrollbars though, what about the old Win32 scrollbars that are still used in a lot of places? Do you skin them to look and act like Windows 11? 10? 8? Vista? Do you change that at runtime by detecting the OS version? Just looking at the scrollbars on my Win 11 install I see at least 4 different scrollbar styles. So which ones do you support?

Say you decide to go the easy route and only support the default Windows 11 scrollbars with the overlay. Fine. They won't look right if you run them on Windows 10 or 8 but whatever. So when when Microsoft releases a new version or changes the behaviour of the scrollbars, you still have to track that and release a new version in step with Microsoft so it doesn't get out of date. If you want everything to be consistent then you have to do it with every widget, not just scrollbars. That's easily several full time jobs just doing that, which no one has been available to do. Because realistically you need people who are expert Windows developers as well as expert GTK developers, and they have to be willing to volunteer to work for free full time because GTK is a volunteer project. As far as I've seen those people just don't exist.

Really though, I don't think it's as big a problem as you're making it out to be since Windows apps are already widely inconsistent with regard to every widget, including scrollbars.

>macOS lets you turn overlay scrollbars on or off at the user level.

Compared to the work of reimplementing everything, it's not particularly hard to push another boolean setting through the code. It's already there on the app level. But like you say, that wouldn't really solve anything.

>they’ve been actively and deliberately gutting stuff useful for other platforms, and refusing to undelete things because of their vision of how things should be

Every project has a vision of how things should be. That's what separates every project from the rest. That isn't why this is happening though; most of the time they're refusing to undelete things because no one is around to maintain them. You don't just bring code back into the project and suddenly it works, someone has to do actual work to make that happen. If you can make a real good case for bringing back that code, and you can show you'll do the work and you won't disappear, then that person could be you. Currently I don't think any maintainers are Windows developers, they're just trying to keep roughly the same amount of Windows functionality working within the time they have available to work on it. Which is not a lot of time.

But I can see you've already made up your mind that the developers are trying to make things worse for you and sabotage you because they don't like you or something, so I doubt I can convince you of anything. This is why I don't enjoy engaging with this forum often. Have a good one.

Re: GUI development with Rust and GTK 4

#168

Earlier quoted context omitted.

> I can't reconfigure a Mac to use Windows keyboard shortcuts. Yes you absolutely can. I've tried it and you can rebind copy/paste/undo/etc globally to use Ctrl-c/Ctrl-v/Ctrl-z/etc, using the builtin Settings.app. It takes about a minute or two, a bit more if you want to change everything as you have to rebind them one by one by hunting down the command names in the menus. You can rebind anything for all apps, or onl…

>Yes you absolutely can. I've tried it and you can rebind copy/paste/undo/etc globally to use Ctrl-c/Ctrl-v/Ctrl-z/etc, using the builtin Settings.app. It takes about a minute or two, a bit more if you want to change everything as you have to rebind them one by one by hunting down the command names in the menus Sorry I don't count that, this is comparing apples to oranges again. It's still not the same as key themes.…

> [...] You're doing the same thing I was talking about earlier, manually reconfiguring every shortcut in every app and dealing with all the resulting bugs yourself. [...] Because key themes were just broken.

OK so what is the ideal solution in your opinion? If key themes are broken, and having the ability to reconfigure a single key (for any single, or all apps) in a central place is also broken, then what isn't? Hardcoding all key combos in the source? Having every app developer build a custom settings dialog where maybe they will, or maybe they won't let you configure a given shortcut?

> Technically, GTK still has an API to create Mac-style menu bars. GNOME apps don't use that API as a matter of convention because GNOME doesn't have a global menu bar like Mac does. If they did, it would be a lot easier to build that same kind of setting GUI. But they don't.

You don't need to draw a menu bar on the screen in order to keep track of the actions that the app exposes to the user.

> It could be implemented in a different way where it always interprets it as Copy even when nothing is selected.

But it wasn't, and that's my entire point. It's your choice to do something that supports and empowers the user, or to throw a wrench in the cogwheels.

> If it's open source you just always have the extra option to recompile if the original developer didn't want to do it.

And if the developer chooses to ignore the needs of their user, the user is free to go somewhere else.

Re: GUI development with Rust and GTK 4

#169

Earlier quoted context omitted.

>Yes you absolutely can. I've tried it and you can rebind copy/paste/undo/etc globally to use Ctrl-c/Ctrl-v/Ctrl-z/etc, using the builtin Settings.app. It takes about a minute or two, a bit more if you want to change everything as you have to rebind them one by one by hunting down the command names in the menus Sorry I don't count that, this is comparing apples to oranges again. It's still not the same as key themes.…

> [...] You're doing the same thing I was talking about earlier, manually reconfiguring every shortcut in every app and dealing with all the resulting bugs yourself. [...] Because key themes were just broken. OK so what is the ideal solution in your opinion? If key themes are broken, and having the ability to reconfigure a single key (for any single, or all apps) in a central place is also broken, then what isn't? Ha…

>OK so what is the ideal solution in your opinion?

Cheeky answer: The ideal solution is a smartphone. It has no keyboard. You don't have to worry about keybindings at all anymore.

Real answer: There isn't one. Once apps can do their own keyboard handling and make their own keybindings, any hope of making a clean solution goes out the window. It's hacks upon hacks from there on, because anything a new app does could potentially conflict with your settings. The Mac solution isn't perfect either but is definitely more flexible and less broken than key themes.

>You don't need to draw a menu bar on the screen in order to keep track of the actions that the app exposes to the user.

Yes, you're correct. GNOME apps could use the app menu API anyway, the menu wouldn't be visible, but some settings GUI could look at the information exposed by the API and use that to do other things. In practice they don't use that API at all because it has no visible effect for GNOME users, and it's not very compelling to require them to use an API that only adds some actions that are hidden away in a settings panel somewhere. Sure you could change this. But you have to convince every app developer it's a good idea to start doing it when they've already taken a lot of steps to move away from menu bars. Including completely removing them from the HIG. I'm not trying to say this is impossible but it's a major change that will affect every app, and you would have needed to do something similar anyway if you were trying to fix key themes to not be so broken.

>But it wasn't, and that's my entire point. It's your choice to do something that supports and empowers the user, or to throw a wrench in the cogwheels.

No, I've seen plenty of apps where Copy with nothing selected takes some reasonable action. Like if you pressed it after opening a dialog displaying a short document, it could copy the entire document for convenience. I can't say no one will ever come up with some reason to do this in a terminal. If it's a Mac terminal, they have few incentives not to because there isn't a key conflict by default with Ctrl-C. If you go around changing your keybindings and you break that, it's on you. Then you probably want to change it back after you find out it's broken. No one can predict what an app will do, that's the point of letting them handle their own keybindings.

>And if the developer chooses to ignore the needs of their user, the user is free to go somewhere else.

By all means, if you like the way Mac handles this, you should use a Mac. Different operating systems are different for a reason.

Re: GUI development with Rust and GTK 4

#170
post #151

Earlier quoted context omitted.

Depends on your goal. Linux can be a project’s primary platform, or you can do a native UI on each platform.

Both options are very time consuming and maintenance heavy building a native UI for each platform. If I were to do that, I would target Windows and Mac first since that is where the users are. Tauri is the obvious choice to target all platforms in the quickest amount of time to market with less native specific maintenance.

You assume every project is commercial. I just make software to solve my problems and I use Linux. GTK is the nicest option to me.
Post reply on HN