Author Archives: Lorenzo Bettini

About Lorenzo Bettini

Lorenzo Bettini is an Associate Professor in Computer Science at the Dipartimento di Statistica, Informatica, Applicazioni "Giuseppe Parenti", Università di Firenze, Italy. Previously, he was a researcher in Computer Science at Dipartimento di Informatica, Università di Torino, Italy. He has a Masters Degree summa cum laude in Computer Science (Università di Firenze) and a PhD in "Logics and Theoretical Computer Science" (Università di Siena). His research interests cover design, theory, and the implementation of statically typed programming languages and Domain Specific Languages. He is also the author of about 90 research papers published in international conferences and international journals.

Neovim and Java with LazyVim, part 1: initial configuration

This is the first part of a few tutorials on Java development with Neovim using the LazyVim setup. I highly recommend LazyVim because it has many cool plugins configured with nice defaults. Moreover, as we see in this tutorial, it lets you quickly have the Java LSP up and running in Neovim.

You need Java installed (possibly 21), while Maven is optional.

I will use this Maven example during the tutorial: https://github.com/LorenzoBettini/maven-bank-example, which is part of my TDD book.

You can follow this step-by-step tutorial by implementing the steps starting from a fresh LazyVim installation (see http://www.lazyvim.org/installation). If you already use LazyVim, you might want to do the steps in this tutorial on a fresh, separate Neovim configuration directory before applying all the configurations in your daily-driver Neovim configuration.

For example, if you start with the starter project provided by LazyVim, you can clone it into a separate configuration directory:

And then you start Neovim pointing to that configuration:

This way, your existing Neovim configuration won’t be touched, and you’ll be free to experiment with this new configuration.

In these tutorials, the path is always intended relative to the Neovim configuration path when referring to a configuration file. If you follow the above commands, for example, it will be relative to “~/.config/lazyvim-java”.

I suggest you try to follow the tutorials by manually executing the configuration steps in such a new separate Neovim configuration.

The final result of this series of tutorials can be found here: https://github.com/LorenzoBettini/lazyvim-java. The “main” branch always points to the latest blog post.

The end of the first part is the branch “first-blog-post”.

A few initial notes

LazyVim comes with autoformatting on save. If you don’t want to disable that in configuration, at least you can use these commands to toggle it during the current session:

  • “<leader> u f” Toggle Auto Format (Global)
  • “<leader> u F” Toggle Auto Format (Buffer)

Moreover, by default, LazyVim is configured to replace tabs with spaces. I don’t like such a behavior globally, so I disable it by adding this line to the existing file “config/options.lua”

To make the tutorial more readable, I will use a few different “light” themes in Neovim instead of the default dark one. Remember that you can temporarily switch the theme with “leader uC”.

Let’s start

If you cloned the above Maven Java example, you can try opening one of its Java files in Neovim:

Without the Java LSP, you only have basic syntax highlighting but no other IDE tooling.

Let’s install the LazyVim “Java Extra”. A LazyVim extra is meant to configure several plugins and configurations with a single mechanism. In this case, it will configure the Java LSP (“jdtls”, the Java LSP provided by Eclipse, implementing all the excellent Eclipse IDE Java development features) and configure other related plugins and keybindings.

You have some alternatives to enable an “Extra”, which is documented for each available “Extra”; for Java, see http://www.lazyvim.org/extras/lang/java. I prefer to use the UI: Type “:LazyExtras” to show the LazyVim Extras UI:

The LazyExtras UI proposes some recommended extras based on the files you’ve just opened, so it should recommend “lang.java”; if not, search for “lang.java” and when you’re on that line, press “x” to install the extra.

You get the feedback about restarting Neovim:

Specifying an extra as we’ve just done creates a file in the configuration, “lazyvim.json”, with this content (the numbers for news and version might be different depending on when you follow this tutorial):

The idea is to keep this file in the Git repository for your configuration as part of your dotfiles for Neovim.

You can now try and open a Java file from this project.

It will not work the first time because Mason has to install the LSP. So, it would try to start the Java LSP (“jdtls”) before it is fully installed. After you see that Mason has successfully installed “jdtls”, you can restart Neovim.

Of course, you could force the installation of “jdtls” by using the Mason UI, “:Mason”: select “jdtls” and install it.

Alternatively, if you want a fully automated solution that, besides installing all the Neovim plugins, also automatically installs the Java LSP, you can add this Lua specification in the Neovim configuration folder (the name does not matter; I call it “extend-lsp” to stress that it extends the Mason configuration of LazyVim, https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/lsp/init.lua) “lua/plugins/extend-lsp.lua” with this content:

Now, when you start Neovim, “jdtls” will automatically install. Remember that “jdtls” is a big Java JAR, so you might want to check whether Mason has successfully downloaded and installed it or is still installing it through the Mason UI.

It works best if you start Neovim from the root directory of the Maven project (the one containing the “pom.xml”). If you open a Java file from another directory, the configured LSP will still search for a “pom.xml” in the parent directories until it finds one (other valid files are the Gradle and Ant specification files if the project is not based on Maven); the root of a Git repository is also a valid root directory.

The highlighting looks much better, with many more highlighted parts (thanks to Treesitter, which the LazyVim Java Extra includes), and you can see the messages from the Java LSP doing its checks and tasks (including downloading Maven dependencies if they are not already cached):

This is a Maven project, so the Java LSP has to resolve the Maven dependencies. If this is the first time you open this project, you should see messages about downloading Maven dependencies.

When all dependencies have been resolved, and the Java LSP has correctly compiled the sources, you can also see some editor decorations (inlay hints), like the parameter names, when calling a method (of course, those parts are NOT part of the source, but only visual content in the editor):

You can enable/disable inlay hints with “<leader> u h”.

With “<leader> c C” you can also refresh “code lens”; for Java, you get the references to classes and methods:

Hovering support (“K”) allows you to see the Javadoc of the current element, e.g., for String:

Pressing any key will make the pop-up window go away. If you want to scroll the pop-up window, use “Ctrl w w” (switch window), and you can scroll the Javadoc.

You’re ready to develop your Java program using typical IDE tooling, like content assist.

Exiting the “insert mode” automatically triggers Java validation, possibly showing warnings and error markers in the editor.

NOTE: The Jdtls LSP (i.e., how LazyVim configures such an LSP by default) creates an Eclipse workspace in the directory “~/.cache/lazyvim-java/jdtls/” in a subdirectory named after the Maven project, e.g., in this example, “~/.cache/lazyvim-java/jdtls/maven-bank-example”. This is just information since you don’t need to care about the created workspaces, which are meant to be ephemeral.

The example used in this post is an Eclipse project. The LSP detects that and possibly updates the Eclipse metadata files accordingly, e.g., “.classpath”, “.settings” directory, “.project”, etc.). If you start with a Maven project (not Eclipse) since the Java LSP is the one from Eclipse, it will create the above Eclipse metadata files automatically for you.

Interestingly, you could use a plain existing Eclipse project, and the Java LSP would still work in Neovim. For example, this is an Eclipse project (not Maven), again part of my TDD book: https://github.com/LorenzoBettini/assertj-log4j-bank-example. It contains the JARs for Assertj and Log4J, and the “.classpath” refers to the JARs that are included. It works seamlessly in Neovim!

Everything works also with multi-module Maven projects; try, e.g., https://github.com/LorenzoBettini/maven-bank-multimodule-example, again part of my TDD book.

You can explore such IDE tooling by modifying one of the existing files.

Otherwise, stay tuned for future blog posts, where we’ll cover:

  • IDE mechanisms provided by this configuration;
  • dealing with Maven dependencies (with the current configuration, editing POM files is not yet ideal);
  • how to run/debug Java programs (with the current configuration, this is not yet possible);
  • how to run tests
  • maybe other features

That’s all for the first part; stay tuned! 🙂

Sway WM: Notifications with Mako

Let’s continue the Sway window manager (in Arch Linux) series I started in my previous post.

In this post, we deal with system notifications. (This post is similar to the corresponding one about Hyprland.)

We use mako, a lightweight notification daemon for Wayland, one of the optional software suggested when we installed Sway. We also need “inotify-tools”:

The nice thing about mako is that you don’t need to start it manually as a service: the first time a notification is emitted, mako will run automatically.

Let’s try to run the notification command:

We see the pop-up in the screen’s top right corner by default.

You can have a look at mako’s manual (5) about its configuration file and where it is searched for:

An example configuration, usable as a starting point, can be found here: https://github.com/emersion/mako/wiki/Example-configuration.

Each time you modify the configuration, you must reload mako by using one of the following commands:

or

With that example configuration, we can emit a few notifications with different “urgencies”, and see the different colors and positions of the boxes:

If you use EndeavourOS, you will get notifications about new updates and when a reboot is required after a system update (the latter is a “critical” notification):

That’s all for this post!

Stay tuned for another post about Sway WM.

Speeding up AUR package installations in Arch Linux

This post can be used for Arch Linux and EndeavourOS.

Recently, a change was committed that highly compresses AUR packages before the actual installation. This takes a lot of time: even on a fast machine, installing something like Chrome or Visual Studio (AUR packages) takes even minutes just for the compression phase. Since I typically remove the generated packages in the AUR cache after installation (e.g., “~/.cache/yay”), the compression is entirely useless to me.

To disable compression altogether, you can edit the file “/etc/makepkg.conf” (requires sudo, of course) and change the line:

into:

And you’re done! Now, even if the string “Compressing package…” is printed on the screen when installing an AUR package, that is actually a no-op.

If you don’t want to change the system file “/etc/makepkg.conf”, you can create this file in your user home, “~/.config/pacman/makepkg.conf”, whose contents take precedence over the ones of the system file. Just put the line:

And you’re done!

Java, Maven and Gitpod, part 4: Maven and Dependencies

This is the 4th post about using Java in Gitpod.

It assumes you have already read the first, second, and third posts.

Let’s now use the POM editor to update the version of JUnit (the Maven archetype is based on an old version of JUnit). When we open the “pom.xml” in the editor, we get a pop-up suggesting installing another extension for analyzing dependencies.

Let’s accept that, as done before, without synching. After the extension is installed, we can visit the corresponding entry in the extensions tab, and, as done before, we use the gear icon to add the extension to our “.gitpod.yml”.

We can then click on the bottom status bar’s button corresponding to the extension (see the one in the left corner in the screenshot) to have an analysis report:

Once it’s finished, we can look at the report. For this simple example, we don’t have any vulnerabilities in our dependencies:

Let’s go back to editing the “pom.xml”; by using the code completion, we can select the newer version of JUnit 4:

Let’s select the latest version (at the time of writing, it is 4.13.2) and let the Java LSP rebuild the project. When we update a dependency in the POM, the analyzer seen above automatically performs another analysis (you can see the feedback in the bottom status bar).

Let’s now explore the “Maven” outline:

We can run lifecycle phases (“compile” in the screenshot above) or single plug-in goals (something I don’t find in the Eclipse Maven support). We can also see the dependencies and their transitive dependencies (“hamcrest” is a transitive dependency of JUnit).

The “Dependencies” entry provides a “+” icon to add a dependency by using the UI. A pop-up will appear where you type a part of the dependency, press ENTER, and see some completions. For example, for log4j:

Upon selection, the POM will be updated. We intentionally selected an old version of LOG4J with a known vulnerability issue to show that the Dependency Analyzer we previously installed detects that:

We can undo the modification we made only for demonstration or use a recent version of log4j (version 2).

We can also create new “Favorites” commands (by pressing the “+” it appears when hovering on “Favorites”). This will open a pop-up for letting us insert a Maven command we want to run often.

For example, let’s insert “package -DskipTests=true”. The favorite will be saved into the Git repository in the file “.vscode/settings.json”. We can also manually tweak it, giving it an alias, e.g., “Create JAR without running tests” (note that we can use content assist in the JSON file):

Now, we have the favorite with the given alias that we can run by using the corresponding triangle:

Speaking of language support for the “settings.json” file, I prefer to disable “autosave”, especially with LSP running in the background, which will continuously ask to synchronize the Java project each time you start modifying the POM. Using the content assist, it is easy to find the corresponding entry and disable autosave:

Stay tuned for the fifth part!

Hyprland EndeavourOS on a PineBook Pro

After installing EndeavourOS on a PineBook Pro, I tried to use Hyprland on this PineBook Pro.

Since I have already blogged about Hyprland a lot, I want to report that Hyprland runs smoothly on this PineBook Pro. I basically reused all my ricing and customizations that I blogged about in my previous posts about Hyprland.

Here are a few screenshots:

That’s all! As I said, this was meant to be a brief report. 🙂

Sway in Arch Linux: getting started

I’m starting a new blog series about Sway, a Wayland Tiling Window Manager (the Wayland version of i3). Though I’ve already blogged about Sway, this post (and a few future ones) are intended as “getting started tutorials”.

I’ll focus on Sway in Arch, in particular, EndeavourOS.

Let’s start by installing EndeavourOS with no graphical environment installed:

Once the installation is finished, let’s log in to a terminal session since we have no Desktop Environment.

Let’s install the main package:

The output shows:

We see some suggestions for packages.

The package “polkit” has already been installed (see above), so we should be fine.

Let’s also install “foot” to be able to open a terminal with the default configuration and also “wmenu” and “dmenu” (see the output above about these programs):

Now, we can start “sway” from the command line.

There’s not much with the default configuration: just the workspace indicator (top-left) and the date and time (top-right), not even a wallpaper (we’ll deal with that in a minute).

We can start a terminal (“foot”) with SUPER+ENTER.

To start an application with the application launcher (by default wmenu/dmenu), for example, “firefox” (if installed) we use SUPER+D and start typing in the prompt appearing in the top left corner; a few letters should be enough til you get to the desired program (and press ENTER to launch it).

Of course, the windows are tiled:

NOTE: the SUPER (i.e., the “Window key”) is the default “mod” modifier for keybindings, but you can change it to something else if you want (e.g., “Alt”).

We can switch workspaces with SUPER+<workspace number>, start other terminals there:

We can focus windows with SUPER+<arrow keys> and move a window to another workspace with SUPER+SHIFT+<workspace number>—and close windows with SUPER+SHIFT+Q.

To move the current window and change its position in the tiling, use SUPER+SHIFT+<arrow keys> (instead of arrow keys, you can also use the H, J, K, and L as in Vim):

Let’s install the package “swaybg” (see the output above; that’s the “Wallpaper tool for sway”):

Now, let’s reload sway with SUPER+SHIFT+C and…

We have the wallpaper!

It’s time to start customizing the configuration.

Let’s create the directory for the configuration file and start from the default one:

Now, we can edit the “~/.config/sway/config” file. (note that the file ends with “include /etc/sway/config.d/*”, which properly sets a few environment variables and makes them available to systemd).

The first thing I will customize is the keyboard layout: I have an Italian keyboard, so I have to specify that (the default is an American layout). I’ll add this section somewhere in the config file (e.g., near the comments about other input configurations):

This will give me an Italian layout by default, and I can switch to an American layout by pressing the right CTRL.

Save the file, reload with SUPER+SHIFT+C, and experiment with the keyboard layouts.

Let’s change the application launcher, which is not very useful in its current shape. Let’s use the Wayland version of Rofi.

Then, let’s open the Sway config file and change the setting of the $menu as follows:

Reload Sway and now pressing the SUPRT+D will get us a much nicer application launcher (just start typing to filter the entries):

Let’s install a file manager, like Nemo.

Then, we can create a shortcut for opening the file manager; let’s open the Sway config file, define a variable for the file manager (it will make it easier in the future to switch to another file manager, for example) and a key binding, e.g., SUPER+SHIFT+ENTER:

Moreover, I prefer Alacritty as a program for terminal:

Then, we just have to change the “$term” definition in the Sway config file: change the line “set $term foot” to

Now, we need an Authentication Agent, which pops up a window asking you for a password whenever an app wants to elevate its privileges. I prefer the KDE one:

And start it when Sway starts; so in the Sway configuration file:

Since this is “exec”, not “exec_always”, you need to restart Sway, not simply reload it.

Now, if we run from a terminal a “systemctl” command that needs superuser privileges, we get the pop-up dialog asking for a password:

The configuration file already contains a commented section for locking and screensaver:

So, let’s install the involved programs (also mentioned above when we installed Sway):

Uncomment the “exec” command; remember that we need to restart Sway to have that mechanism in action. (Of course, you have to wait for 300 seconds). I’m not covering customization of the lock screen and the like here.

We can also set a key binding to lock the screen manually. I usually use SUPER+L; note that this is already bound as a combination to move on the left window (remember the Vim keybindings above?); so, first, I have to uncomment the corresponding bindings (I uncomment them all because I’m not using them: I prefer arrow keys) and add mine:

Let’s install some of the optional packages suggested above when installing Sway (in particular, the “xorg-xwayland” will allow us to run also X applications):

That’s all for this first tutorial part; stay tuned for more to come 🙂

Java, Maven and Gitpod, part 3: Configuring Java

This is the 3rd post about using Java in Gitpod.

It assumes you have already read the first and second posts.

On the bottom, we can see that there are two warnings on our project; let’s click the icon and see them in the “Problems” tab:

Since this is not a Java project managed by Visual Studio Code but a Maven project, we must fix the warning in the POM.

Let’s assume we want to update our project to use the Java version installed in the Gitpod workspace: Java 11 (we can tell that from the warning, but we could also run “java -version” from a terminal to verify that). We open the POM file and update the corresponding properties of Java 1.7: we change “1.7” to “11”:

As soon as we modify the POM, we get a pop-up: the Java LSP detects a change in the project configuration and offers to synchronize the classpath and rebuild the project. Of course, we accept. We accept that, and after a few seconds, the warnings go away.

Note that our choice leads to creating the settings file for this option. We can choose to rebuild the project automatically (“Always”), and the settings file will be updated accordingly. Of course, it makes sense to store such a file in the Git repository.

We can now create a commit with our changes and push them to GitHub.

Remember that the JSON editor is aware of the corresponding schema, so we can enjoy code completion for the string value:

Let’s now say we want to use Java 17 for our project. The workspace provides Java 11, so we must also have Java 17 installed in the Gitpod workspace.

Let’s modify the POM for Java 17 and rebuild the project. Let’s try to run the main file. The Java application still runs, as we can see from the terminal:

Gitpod workspace uses SDKMAN to provide a few versions of tools like the JDK and uses the version required by the project (in this example, Java 17).

We can list the installed JDK in the terminal (and the current one):

If we wanted to go for Java 21, we should install that version with SDKMAN, but we wouldn’t want to do that manually each time we open a Gitpod workspace. Moreover, instead of the “Zulu” distribution, we might use the “Temurin” distribution.

The recommended way is to provide a custom Dockerfile for our Gitpod workspace to have full explicit control over the versions of the tools we use; this will be part of the Git repository and live with the code.

So we create in the root of our project the file “.gitpod.Dockerfile,” and we configure SDKMAN for the version of Java we want to install and set as the current (the available versions can be discovered with “sdk list java”):

Then, we refer to this Dockerfile in the “.gitpod.yml”:

As before, we can let Gitpod validate our configuration and start a new workspace with the rebuilt Docker image.

As shown in my previous post on Gitpod, you might want to start from a smaller base image with only the needed tools like Java. That would decrease the time to build the custom Docker image. That is out of the scope of this post.

However, rebuilding the Docker image will be done the first time you start a workspace, and the custom image will be cached.

On the new workspace, we can verify that we are using the Java version we installed and set as default:

Again, we commit our changes (including the new custom Dockerfile) and push them to GitHub.

One could use the same strategy for installing a specific version of Maven through SDKMAN. Maven is also installed in the workspace through SDKMAN.

I want to conclude that this process seems long. Still, once you get familiar with the configuration of Gitpod for Java/Maven projects, for new repositories of the same kind, it is enough to immediately put in the Git repository the “.gitpod.yml” and the “.gitpod.Dockerfile.” You can immediately start coding with Gitpod! 🙂

Remember, though, that the first time, you will still have to wait for the build of your custom Docker image.

Stay tuned for the fourth part.

How I manage Neovim configuration with Chezmoi

I love to manage my dotfiles with Chezmoi, which I highly recommend! In a single Git repository, I have common dotfiles and Window Manager specific (KDE, GNOME, Hyprland, and Sway).

However, I prefer to have my Neovim configuration in another Git repository, separate from my Chezmoi dotfiles. I’ve just started learning Neovim, and I’m not yet 100% sure the configuration I use will be the ultimate one (I use Lazyvim); that’s why I want to keep them separate.

Chezmoi offers mechanisms for such situations: https://www.chezmoi.io/user-guide/include-files-from-elsewhere/. In particular, I use “Include a subdirectory from a git repository”: this way, Chezmoi will clone the external Git repository for my Neovim configuration on the first run and will keep it up to date (i.e., “git pull”) at some specified intervals (remember, the default interval is 0!).

You need to create the file “.chezmoiexternal.toml” in the root folder of your Chezmoi file and follow the syntax in the documentation.

For example, I want my “~/.config/nvim” directory (where Neovim configuration lives) to be populated (and kept up-to-date) with the contents of my GitHub repository “https://github.com/LorenzoBettini/starter” (as I said above, I’m using a fork of the Starter repository of Lazyvim):

Note that I specified a 1-hour refresh interval. Thus, if I issue a “chezmoi update,” it will keep that interval into consideration when deciding whether to check for updates (i.e., “pull”) in the Git repository. However, you also have this option in Chezmoi to force the Git update:

That’s all, and enjoy your dotfiles! 🙂

Installing EndeavourOS ARM on a PineBook Pro (August 2024)

I have already blogged about installing EndeavourOS ARM on a PineBook Pro (and previously, directly Arch ARM: the first article and the second article).

This blog post will describe the new procedure for installing EndeavourOS ARM on a PineBook Pro.

As usual, the instructions can be found here: https://endeavouros.com/endeavouros-arm-install/. Previously, there used to be three possible ways to install the system. Now, if we’re not considering the headless server installation, there’s only one way.

First, download the installation image (“.img.xz”) from the above page. For the PineBook Pro, I downloaded “enosLinuxARM-pbp-latest.img.xz“.

This image must be flashed on the final installation medium. I will install EndeavourOS ARM for PineBook Pro on an SD card in this blog post. The idea is that you then boot the PineBook Pro with such a flashed medium, and the installation procedure will finalize the installation on the same medium; during the textual installation, you specify a few configurations.

Of course, the flashing can be performed on any computer, not necessarily from the PineBook Pro.

The delicate part is ensuring you get the name of the flashing device properly or you wipe a device completely. You can use the command “sudo fdisk -l” to get the list of all the devices.

In my case, the inserted SD card is “/dev/sda“, so I flash the image as follows (again, BE COMPLETELY SURE of the correct device!!!):

Be patient; this will take a few minutes, especially depending on the speed of the SD card.

Then, it’s time to boot the PineBook Pro with the SD inserted.

I’m assuming you already have a boot program that allows you to select the booting device. For example, I have “Tow-Boot”.

At some point, I press ESC to select the booting device:

The textual installation starts.

Remember, it will install the system on the same device you used to boot.

Here are some required information:

Of course, you’ll also be asked for your username and password.

Then, you select the Desktop environment (or no desktop at all):

I selected KDE Plasma. Here’s the summary.

After a few minutes, you should get:

Time to reboot!

Unfortunately, at the first reboot, selecting SD to boot into the installed system brought a failure that no bootable image could be found. However, rebooting and selecting SD again succeeded.

IMPORTANT: as you noted, you have no choice about partitioning and filesystem type: you will get EXT4. To be honest, I never managed to setup BTRFS with the previous EndeavourOS installation anyway.

I could finally land on the newly installed KDE Plasma.

I’d suggest doing some configurations and tweaking, e.g., you need to configure swap since 4 gigabytes of RAM are too few! You could go for a swap file, but I’d recommend using zram as the primary swap.

Enjoy your EndeavourOS ARM installation 🙂

Eclipse in Hyprland 0.43

I hadn’t used Eclipse in Hyprland for a while. It used to work correctly; however, starting from somewhere in version 0.41, something broke, and it’s still broken in the current (at the time of writing) version 0.43.

When I execute Eclipse in Hyprland, i.e., in Wayland mode, the trees in Eclipse, e.g., Package Explorer (but also Project Explorer or the Outline) are displayed correctly until you start expanding the tree or hover with the mouse: the elements of the tree gets corrupted and disappear:

Till the whole tree disappears:

I reported the bug (https://github.com/hyprwm/Hyprland/issues/7829). The bug was closed because it had already been reported: in the beginning, the bug talked about DBeaver, which I didn’t know is an Eclipse-based application: https://github.com/hyprwm/Hyprland/issues/6844. The problem is associated with a previous hack to avoid flickering in the Qt application. Unfortunately, the hack breaks Eclipse-based applications, and it’s still there at the time of writing.

If I want to use Eclipse in Hyprland, I have to run it in X11 mode, i.e., by prefixing its execution with the corresponding environment variable set:

Since I have Hyprland with scaling enabled (1.5) Eclipse in X11 mode (Xwayland) gets pixelated:

To avoid that, as documented in Hyprland, I have to disable XWayland scaling by adding this section in “~/.confgi/hyprland/hypr.conf”:

Now, Eclipse runs in Xwayland without flickering but it’s unreadable to me (after all, it is not scaled):

We can scale it with the environment variable “GDK_SCALE”, but that does not support fractional scaling: set it to 2, and then Eclipse gets too big:

However, I can use another environment variable, “GDK_DPI_SCALE”, which scales text only (not icons; better than nothing!);

Here’s how I run Eclipse:

And here’s the result (readable and not too big):

Let’s hope the Hyprland problem gets fixed soon…

Sway: monitor configuration for different computers

I’m using Sway (not as my daily driver) on different computers: PCs and laptops.

For the PCs, I’m using an HDMI monitor. Laptops have different display sizes, e.g., small displays with low resolution and more extensive displays with retina resolution. Thus, I need to set different scaling factors for the different displays.

It’s pretty easy in Sway, and I’ll detail that here.

First, you need to get the information Sway uses to refer to your current monitor:

For example, on my LG GRAM 16, I get:

I want to scale at 1.6 on this computer. Otherwise, I can’t read almost anything.

In “~/.config/sway/config”, I specify scaling for this computer using the name shown above

Reload the configuration, and now scaling is correctly applied when using this laptop.

On the other laptops (e.g., my Acer Aspire Vero), I repeat the same procedure: get the identifier and add a specific configuration with the identifier; for example, for this other laptop, 1.25 scaling is enough:

For HDMI monitors, I want 1.5:

Summarizing, this is the monitor section in my Sway configuration, which automatically sets the desired scale factor according to the computer I’m using:

Of course, you can change many values for each monitor, including resolution and orientation, by specifying the corresponding identifier.

In my case, I only want to change the scaling factor.

Better KDE theming and styling in Hyprland

Recently, I blogged about using KDE applications in Hyprland. I also blogged about theming and styling them. However, I’m not very happy with that solution, so I’ll provide a possible alternative, which, in my opinion, is better. Some of the steps are similar to the ones in my previous post.

I assume you’ve already installed a few KDE applications, like Dolphin, Konsole, and Kate (see the blog post above).

As in all my Hyprland posts, this is based on Arch Linux; I mainly use EndeavourOS.

Let’s install a few packages:

The crucial ones are the “qt5ct” and “qt6ct-kde” packages. We’ll use the latter but also install the former for possible old Qt 5 applications, just in case. The “Hack” font is the standard KDE monospace font, and Kvantum is the theme engine. Finally, “breeze” will install the Breeze color schemes we will use in qt6ct.

IMPORTANT: we use the AUR package qt6ct-kde, which is a patched version of “qt6ct”. If you installed packages, as in my previous post on this subject, you’ll have to replace “qt6ct” when installing this AUR package.

Then, we have to set this environment variable in “~/.config/hypr/hyprland.conf” (note that we specify qt5ct, but for Qt 6 applications, qt6ct will be used automatically):

Let’s restart Hyprland (I’m assuming “env = QT_QPA_PLATFORM,wayland” is also set).

That’s the standard style of Dolphin, Kate, and Konsole with the default settings:

Let’s open the “Qt6 Settings” application (corresponding to “qt6ct”).

Remember that Qt6 settings will be stored in the file “~/.config/qt6ct/qt6ct.conf”.

First of all, I’m changing the fonts to match the standard ones of KDE:

Remember always to click “Apply” after changing something”.

By restarting the above applications, the fonts now look like in a standard KDE system:

Now, benefitting from the patched qt6ct package, differently from my previous post, we can select the “Breeze” style; similarly, we can select “Breeze Dark (KColorScheme)” in color:

Let’s see the results:

Super! Everything looks great with the above simple setting!

If you look at my previous post without the patched version of “qt6ct”, we had to select the “Breeze Dark” icon to have nice-looking icons in the dark style. Now, we didn’t have to!

Moreover, Kate also automatically uses the dark breeze theme (compare that with the previous post):

Note that you can tweak other settings in qt6ct further.

In particular, you can install other icon packages and select another icon set in qt6ct.

Of course, you could also directly use Kvantum themes, as we saw in my previous post. However, with the patched “qt6ct”, having a nice-looking and consistent theme for KDE applications is much easier.

Happy (better) theming! 🙂

Waybar Workspaces in Hyprland

Waybar has a dedicated module for Hyprland workspaces: https://github.com/Alexays/Waybar/wiki/Module:-Hyprland#workspaces. One of its most fantastic features is the possibility of representing the application windows in each workspace.

For example, here I have the workspaces with the following application windows:

  1. Kate (text editor) and terminal (Alacritty)
  2. Dolphin (file manager)
  3. A Firefox window and a Firefox window on GitHub
  4. A Firefox window on YouTube and Thunderbird (email client)

Here’s the Wyabar workspace representation (on the left):

Here I added Google Chrome in the workspace 2:

This is the Waybar module configuration, where the important thing is “{window}” in the “format”. Unfortunately, you must work on defining the rewrite rules and the icon to show as you want. Moreover, these are not icons; they are characters from Nerd fonts:

Probably, your browser will not render the fonts (though you can copy and paste them, and they will be taken correctly). I’m also showing a screenshot of my text editor where the Nerd fonts are rendered correctly:

Of course, you also have a character to be used by default if nothing matches (e.g., a question mark).

Nice feature, isn’t it? 🙂

Downgrading packages in Arch Linux Arm

In Arch Linux, you can easily downgrade packages with the script https://github.com/archlinux-downgrade/downgrade, also available from AUR.

I experienced problems with the new version (2:2.11.1) of wpa_supplicant in PineBook Pro, where I have EndeavourOS. WiFi does not work anymore with the new version of wpa_supplicant.

I tried downgrading as suggested in the EndeavourOS forum. However, I got this error:

That’s because, by default, the downgrade script uses this archive site https://archive.archlinux.org or the local cache (which I always clear). However, that archive is for the x86 architecture. You must use a corresponding archive for the arm architecture, like https://alaa.ad24.cz/, using the command line option:

So I ran (note that I also chose to add the package to “IgnorePkg” to avoid further future updates, at least until the bug is solved):

When running the command, you get the possible versions to downgrade to:

Reboot, and WiFi works again 🙂

Multibooting Fedora and Arch with GRUB

I have already blogged about multibooting several different Linux distributions with GRUB.

This post is a simplified and updated version of the previous post.

Moreover, I made it easier to test such configurations manually: install several Linux distributions in a single KVM virtual machine.

In this post, I’ll show how to configure GRUB (without os-prober, which doesn’t work well with different Linux distributions like Fedora and Arch) by delegating to other GRUB configurations (i.e., chain loading).

I’ll use Arch EndeavourOS (BTRFS) and Fedora. I’ll show the two possible solutions: EndeavourOS as the main GRUB delegating to Fedora and vice-versa.

First, we need to tweak both distributions’ GRUB configurations.

Preparing EndeavourOS

We must tweak the EndeavourOS GRUB UEFI entry. Otherwise, when trying to boot Fedora, you return to UEFI (this has been a known problem/choice for some time).

The easiest way is to remove the UEFI entry simply:

Or, if you want to keep a backup:

As a further alternative, if you want to keep the UEFI entry, you must remove the culprit call

As usual, you must run “grub-mkconfig”.

Preparing Fedora

It’s better to remove os-prober since, as I said above, it wouldn’t work for other Linux distributions, and it takes some time when updating GRUB: edit with sudo the file “/etc/default/grub” and ensure you have this line:

Also, ensure you have this line (if you use EndeavourOS as the principal GRUB, otherwise you will not see Fedora entries):

But then, you’ll have to update GRUB after you install a new kernel. (if you use Fedora as the principal GRUB, the above modification is unnecessary).

Then, run

Booting EndeavourOS from Fedora

Detect the partition of EndeavourOS, e.g., with “lsblk”. (remember that I’m testing this in a KVM virtual machine where I have installed both distributions; thus, partitions will start with “vd”; they are virtual disks).

EndeavourOS is in “vda3”.

Edit the file with sudo “/etc/grub.d/40_custom”

Add this entry (for more details on these entries, please see my old post):

By default, Fedora does not show the GRUB menu, which would break this post’s intent.

To show the grub menu, run:

Update GRUB:

Reboot the virtual machine configured to start with Fedora, and you’ll see the EndeavourOS entry to boot EndeavourOS (you will get to the EndeavourOS GRUB entries from the Fedora GRUB):

Booting Fedora from EndeavourOS

As done above, inspect the partitions:

Fedora is in “vda2”:

Edit with sudo “/etc/grub.d/40_custom” and add this entry:

Update GRUB:

Reboot the virtual machine to start with EndeavourOS, and you’ll see the Fedora entry to boot Fedora (you will get to the Fedora GRUB entries from the EndeavourOS GRUB):

Final notes

Fedora has its way of updating the system, which requires rebooting, installing updates, reboot again. This process doesn’t work well when Fedora is not the principal booting system; at least, it requires attention to manually select the Fedora entry a few times during this update/booting process. Thus, it’s better to keep Fedora as the principal booting system.

Problems with xdg-desktop-portal-kde as well

I recently blogged about some problems with UI tests in GNOME due to xdg-desktop-portal-gnome.

Unfortunately, I also started to experience problems similar to those with KDE Plasma 6.1 (Linux EndeavourOS and Arch); as in the other blog post, the problem is only with Wayland.

I’ll use this example project (taken from my TDD book): https://github.com/LorenzoBettini/demo-attsw. It is a simple Java Swing application where UI tests are written with AssertJ Swing. I run “mvn verify,” and most of the UI tests fail (when the AssertJ Swing bot tries to interact with the application window, it mostly gets the position wrong). This is the leading cause of the failure: I get this dialog popping up from KDE, “Remote control requested”, coming from “xdg-desktop-portal-kde“:

This shows up as soon as one of the UI tests starts.

First, I must click “Share” (of course, tests have already failed). Note that the dialog remembers the setting for the application you used to run the tests. For example, if you change the Java version to run the tests, you’ll get the dialog popping up again.

Starting the UI tests again still leads to failures. I have to change these system settings:

Now, UI tests finally succeed. Though, they tend to be quite flaky. I see that while they run, since they interact with the keyboard and mouse, other windows get focused, and some interactions are performed on the other windows, not one of the applications under test. Things improve if you only leave the application under test on the screen. It is even better to place the mouse in the part of the screen where the application under test usually appears.

In general, with such kinds of UI tests, it might be better to switch to X11… 🙁

A first look at Fedora 40 Sway

I started to look at the Window Manager Sway. Hopefully, in the future, I’ll post more articles on that.

In the meantime, I looked at the Fedora Sway spin (the current version is 40) and will briefly comment on that in this post.

The live environment already provides a Sway window manager and leaves documentation about how to start programs, especially the installer:

Let’s follow the suggestion and select the installer:

The installer is the usual Fedora one:

However, the next part is different from what I have always seen in a Fedora installation, at least the default Gnome one: you have more things to set:

I won’t show the other installation parts since they are standard in Fedora installation. I went with the defaults because I’m trying that in a virtual machine, so I’ll stick with the default partitioning scheme.

After the installation is concluded, let’s restart, and here’s the greeting login screen:

And once you log in:

No more help message: you’re on your own 😉

Probably, a basic knowledge of Sway is required and assumed.

At least, you may remember the SUPER + d shortcut to open the application launcher, and you can run something from there.

It’s better if you know about the basic shortcuts, which are the Sway default in this installation:

  • SUPER+SHIFT+Q: close the current window
  • SUPER+ENTER: run the default terminal, which here is “foot”
  • SUPER+SHIFT+C: reload Sway

The look and feel of the installed and configured Sway is nice; the “Waybar” is configured with a few helpful information. You have the tray icon (on the right) for network connections—the volume control opens a dialog to configure the volume and microphone. Moreover, media keys are already configured. For example, the ones for volume, and you have a visual feedback:

A few screenshot key bindings are also configured:

# Capture the currently active output
Print
# Capture the currently active window
Alt+Print
# Select and capture a custom rectangular area
Ctrl+Print

However, you have no visual feedback for such features; more effort could have been made.

Software-wise, you don’t have much installed: you have Thunar as a file manager but no text editor, for example.

The disappointing part is the configuration of Sway: you might expect you have everything already created in the “~/.config” subdirectories, following the standard Sway and other application structures. Unfortunately, it’s not like that: you have nothing in your home directory in that respect. Everything is configured system-wide. Of course, you can customize everything, but you must go through the documentation: https://docs.fedoraproject.org/en-US/fedora-sericea/configuration-guide/.

Several precedence rules are documented in the link, but I find that mechanism quite cumbersome. There are configuration files spread in many places:

You have to add additional files to your home folder or completely override a configuration file with one with the same name in your configuration folder.

I’ve just started experimenting with Sway; such a mechanism is hard to grasp and use.

For example, the installation procedure completely forgot the “Italian” layout I specified for the keyboard! There’s no “~/.config/swat/config” file to modify quickly. Should I copy the default one there and modify it; however, the part about the keyboard layout is not even commented on.

After reading the documentation, I came up with this (the configuration file’s name is my own; I haven’t followed a pattern; the important thing is the directory where the “.conf” file is):

Then, I reloaded Sway with SUPER+SHIFT+C and got the Italian keyboard layout.

But it wasn’t easy…

In general, I had the impression that Fedora Sway is not for beginners of Sway; however, it doesn’t seem to be for Sway experts either: they’d expect to customize Sway as they see fit anyway, and probably they have their dotfiles ready to be used.

However, maybe Fedora Sway is not bad for starting to experiment with Sway in the end. 🙂

Environment Variables in Sway

Setting environment variables in Hyprland is easy: just put them in its config file. Setting environment variables in Sway is a bit harder, and there seems to be some confusion. The documentation is unclear about that, at least in my humble opinion.

This blog post documents my way of setting environment variables in Sway.

Let’s install qt6ct for some experiments.

If we run it, we get the following problem:

Where can environment variables be specified when using Sway?

In my experiments, “~/.profile” is not loaded (either when logging in or using SDDM). Instead, “~/.bash_profile” and “~/.zshenv” should be used for BASH and ZSH, respectively.

So, in those files, source “~/.profile” explicitly

Let’s put the environment variable declaration and export into “~/.profile”

Exit Sway and get back in, and now qt6ct is happy:

If we want also to have our environment variables available to systemd, we can follow another strategy to specify environment variables in one place.

First of all, let’s create a file (or any, if you want to have several environment variables categorized in different files) that ends with “.conf” in the directory “~/.config/environment.d/”.

For example, I have “~/.config/environment.d/10-env.conf” (these files are read by systemd alphabetically); I move the environment variable definition in this file (so, I remove it from “~/.profile”):

Note that in this file, you only have to use the syntax “key=value” (to see the full syntax: https://www.freedesktop.org/software/systemd/man/latest/environment.d.html)

Each time you modify that directory, you have to run this command:

To verify that systemd read this file, run

And you should see the line:

If you restart Sway and run qt6ct, you will see that qt6ct complains again. The environment variable is only visible to the systemd. We have to export the variables read by systemd.

To avoid duplication, we can use the program “/usr/lib/systemd/user-environment-generators/30-systemd-environment-d-generator”, which does precisely that (of course, it handles all the environment variables in the “.conf” files in the environment.d directory). In “~/.profile” we now put this line:

Restart Sway and run qt6ct, and now everything went back to work!

You can also open a terminal from Sway and verify the environment variable is there!

I hope you find this blog post helpful 🙂

Modifier-only shortcuts in KDE Plasma 6.1

Before KDE Plasma 6.1 (released a few days ago and already available in Arch), if you wanted to configure a “modifer-only” shortcut (e.g., SUPER key, also known as META, to activate the “Overview” effect), you had to manually modify the “~/.config/kwinrc” file and add these lines:

Another example is if you wanted the SUPER key to activate the “Present Windows” (AKA “Expose”) effect:

In Plasma 6.1, modifier-only shortcuts must not be specified in “~/.config/kwinrc”: they are in “~/.config/kglobalshortcutsrc” and, as such, can be visually specified through the standard KDE shortcut system settings:

By default, SUPER is configured to start the “Application Launcher” (this means that previous specifications in “ModifierOnlyShortcuts” in “~/.config/kwinrc” are not considered anymore).

If we want to assign it to “Overview”, we first search for current shortcuts for “Overview”:

Click on “Add custom shortcut” and press SUPER. You are notified about an existing binding for the “Meta” key:

And, of course, we choose to reassign it.

Done!

Thus, such a setting will be stored in “~/.config/kglobalshortcutsrc”:

Nice feature, though it breaks existing configurations, which need to be adapted 😉

KDE theming and styling in Hyprland

Recently, I blogged about using KDE applications in Hyprland.

But what about theming and styling them?

I’ll show how to do that in this blog post, assuming you’ve already installed a few KDE applications, like Dolphin, Konsole, and Kate (see the above-linked blog post).

WARNING: the strategy shown in this post is not optimal, in my humble opinion. There’s a more recent post where I show a better strategy (in my opinion).

As in all my Hyprland posts, this is based on Arch Linux; I mainly use EndeavourOS.

Let’s install a few packages:

The crucial ones are the “qt5ct” and “qt6ct” packages. We’ll use the latter but also install the former for possible old Qt 5 applications, just in case. The “Hack” font is the standard KDE monospace font, and Kvantum is the theme engine.

Then, we have to set this environment variable in “~/.config/hypr/hyprland.conf” (note that we specify qt5ct, but for Qt 6 applications, qt6ct will be used automatically):

Let’s restart Hyprland (I’m assuming “env = QT_QPA_PLATFORM,wayland” is also set).

That’s the standard style of Dolphin, Kate, and Konsole with the default settings:

Let’s open the “Qt6 Settings” application (corresponding to “qt6ct”).

Remember that Qt6 settings will be stored in the file “~/.config/qt6ct/qt6ct.conf”.

First of all, I’m changing the fonts to match the standard ones of KDE:

Remember always to click “Apply” after changing something”.

By restarting the above applications, the fonts now look like in a standard KDE system:

Let’s try to change the appearance colors to a darker setting in the palette:

Unfortunately, the result is a small disaster:

Dolphin is the only application that reacted to the change but in a wrong way.

Instead, let’s revert to the default palette and change the Style to Kvantum (“kvantum-dark”):

The result is improving:

However, it’s still ugly: the icons are mostly invisible, and the Konsole menu bar does not like this change.

Let’s fix the icons first: we select “Breeze Dark.” (Remember: We installed them at the beginning.)

The result has improved: icons are better visible, and in Dolphin, folder icons all look fine:

The rest of the ugly look is due to the default Kvantum theme.

So, from now on, we can try to select a Kvantum theme that makes the KDE applications look nice.

Let’s open Kvantum (“Kvantum Manager”) and try with another theme, e.g. “KvAdaptaDark”:

Now KDE applications look better:

Unfortunately, there’s a white bar in Konsole.

Moreover, Kate does not use the dark settings for the editor. However, Kate allows you to select a color scheme:

For example, by selecting “KvAdaptaDark” here as well, we get a nice-looking Kate:

Remember that Kvantum settings will be stored in the file “~/.config/Kvantum/kvantum.kvconfig”.

Now, you can experiment with other Kvantum themes.

For example, this is “KvArcDark”, which still has problems with Konsole menus:

Or “KvGnomeDark”, which doesn’t look bad after all (probably it’s the best up to now: we don’t even have the white bar in Konsole):

You can further tweak each Kvantum theme and change other settings in qt6ct.

In particular, you can install other icon packages and select another icon set in qt6ct.

Stay tuned for another post for styling Qt and KDE applications.