Lenovo ThinkPad T15 Gen 2 and Ubuntu Linux

I recently got my first Lenovo ThinkPad laptop and it’s a T15 Gen 2 (G2). I’ve decided to give a ThinkPad a try, since Lenovo provides a 3-year warranty with on-site support and they supposedly have great Linux support. At least this one is officially supported – it has a Linux specific manual here. However my came with Windows 10 Pro installed.

Update after 8 months of usage

Today I am using Manjaro 21.3.2 with Gnome 42. All the problems I wrote about below were fixed, but I don’t think Manjaro is to thank. Only one new small annoyance was introduced: when I restart the system, I have to manually start Bluetooth by clicking “Turn on” in the Gnome top-right system drop-down menu. I think it’s a great Linux laptop so I bought another for my part-time employee 🙂

My TL;DR experience with Ubuntu 21.10 and this laptop is: it works, but I still have some issues.

The exact model is 20W4003FGE and it has the following specs:

  • CPU: 11th Gen Intel Core i7-1165G7, 4 cores and 8 threads total
  • RAM: 16 GB DDR4 3200, but I added another 16 GB (Crucial CT16G4SFRA32A)
  • Storage: SSD 512 GB M.2 PCIe 3.0 x4
  • GPU: Intel Iris Xe
  • Display: 15.6″ Full HD IPS 60 Hz
  • Connectivity: Thunderbolt 4, Wi-Fi 6, Bluetooth 5.2
  • Security: TPM 2.0, IR-camera, Fingerprint reader

The first thing I do with a new laptop now is to make a disk image in the state as it was delivered, before booting the machine for the first time. I use Macrium Reflect for this and save the image on an external drive. So after I did that, I booted it up so I could take some performance benchmarks to compare with Linux afterwards, just out of curiosity. Also, I snatched the Windows licence key, so I could legally install the same Windows in a Virtualbox and have it activated. You can get the key by opening PowerShell and entering the command:

wmic path softwarelicensingservice get OA3xOriginalProductKey

Then I installed Ubuntu 21.04 with drive encryption. I was really busy so I wasn’t able to fully configure the system at once, so I waited for 21.10 to come out to finish setting it up. Ubuntu 21.10 ships with kernel 5.13.0 and Gnome 40 and it runs Wayland by default.

Running Ubuntu Linux

Cool stuff that works out of the box:

  • All function keys, including keyboard back-light control
  • Fingerprint sensor for login/screen unlock
  • Power plan switching

Issues that I am still facing:

  1. Normally, the fan should decrease the speed after CPU usage goes down. But this laptop keeps blowing for a couple of minutes more after the CPU heavy task has completed, while the performance monitor shows a CPU temp in the 40° C and it feels pretty much cool on touch. In other words, it does not react that well to stress and it bugs me that it’s blowing for no apparent reason. Running Balanced or Performance power plan does not seem to make any difference regarding this.
    UPDATE: this is not a problem anymore on kernel 5.15.
  2. Relevant to #1, the fan keeps blowing even after suspending the machine. That seems crazy to me… is it designed to keep blowing while being carried around in the bag? I hope it’s something I can fix.
    UPDATE: this is fixed by selecting the legacy power plan in UEFI settings.
  3. The display is an IPS but it really has bland colours. I am not sure what is the cause behind this. I hope I can improve it.
    UPDATE: on Manjaro 21.3 (Gnome 42) this does not seem to be a problem any more. Or maybe it was fixed by one of the many firmware updates that came out and I applied. It’s hard for me to tell, since I don’t use the laptop screen unless when out of office. However, looking at this color intensive video side by side on the laptop screen and an external monitor, it’s not as bad as I remember it from the beginning. So I would consider this one fixed also.

I will update this article when I fix any of these.

Apart from this, it would be nice to have an automatic power plan switcher so that it switches automatically to Performance when plugged, Balanced when on battery and Power saver when the battery is low.

Performance

Regarding performance, I ran Geekbench and Unigine Heaven on both operating systems.

Unigine Heaven, high qualityGeekbench CPUGeekbench Compute
OSKernelFPSScoreMin FPSMax FPSSingle coreMulti coreOpenCLVulkan
Windows 1047.7120215.794.9157752811741016628
Ubuntu 21.105.1347.1118524.190.916605693/9058
5.1447118423.189.416585656/9611

I did the benchmarks while the laptop was plugged in, after a fresh system start and the power plan was set to Performance. But while Unigine Heaven has similar overall performance on both systems, the Vulkan Compute test is obviously worse on Linux. However, I haven’t investigated if this is some kind of a problem or misconfiguration that has an easy fix. I tried kernel 5.14 but it did little to improve.

Honestly, before deciding on the purchase, I haven’t checked what the Iris Xe card really is – all I wanted is to avoid nvidia discrete GPU models with switching graphics, because I had problems with those previously while attempting to use external displays. But it seems this laptop could do some light 3D gaming, if this is something you would be interested in.

Conclusion

While it’s a bit early to draw any conclusion, it’s a laptop I would generally recommend to anyone looking to run Linux on it. I just started using it as a daily driver and can’t comment on the battery life, but I am sure it will turn out to be a decent machine for professional users.

I will update this article later again with any new information.

Adding pgettext (gettext context) support to PHP

TL;DR: Packagist Version

It seems the PHP team completely forgot about adding support for gettext context functions, so I implemented them based on what I found in this Stack Overflow answer.

The functions signatures (names and parameters) are what I’m seing in C and Python.

So, if you want to use them – here it is. However, you are probably using composer so you are going to use this:

  1. In your CLI:
    composer require datalinx/gettext-context
  2. Include the vendor/datalinx/gettext-context/src/gettext-context.php file when you need it*

* It’s not added to the autoload directive, since you might not need or want to always include it in runtime. If you want to always load it, just add the source file to your composer.json autoload files list:

{
    "autoload": {
        "files": [
            "vendor/datalinx/gettext-context/src/gettext-context.php"
        ]
    }
}

Now you have pgettext, npgettext, dpgettext, dnpgettext function ready to use in your PHP code.

The functions are documented and fully tested.

Extracting messages with context support

If you are using the xgettext CLI utility, you can add extra keyword parameters to include the context functions. For example, this would be used in our package:

xgettext --force-po --keyword=pgettext:1c,2 --keyword=npgettext:1c,2,3 --keyword=dpgettext:2c,3 --keyword=dnpgettext:2c,3,4 -c -o messages.po tests/Test.php

If you’re using Poedit, add the following keywords in your Catalog > Properties > Sources Keywords:

  • pgettext:1c,2
  • npgettext:1c,2,3
  • dpgettext:2c,3
  • dnpgettext:2c,3,4

Using Dell D3100 USB3.0 dock with Ubuntu Linux

If you are considering buying this universal USB “dock” to use it with Ubuntu Linux, I say: go for it. It just plain works.

Basically all you have to do is hook it up and install the DisplayLink driver.

I am currently (March 2020) using it with my Asus TUF Gaming FX705GD laptop with Ubuntu 19.10 as described in my other article.

You do have to know that using a DisplayLink dock will never be the same as hooking the external monitors directly to the laptop, since it uses compression to deliver the image to the monitor. This is most noticeable when scrolling – it’s just not as smooth.

Regarding CPU usage, there is a slight increase but is barely noticeable and completely inconsequential, at least with one Quad HD (2560×1440 px) monitor.

Hot-plugging works perfectly. However when setting it up, it might display some distortion or artefacts around the mouse cursor. To fix this, all I needed to do was log out and back in.

Basically I would gladly recommend this dock, though I have not tried an UHD/4K or multiple monitors.

Asus TUF Gaming FX705GD and Ubuntu Linux

UPDATE: everything works out-of-the-box with Ubuntu 20.04 LTS.

For anyone considering buying this laptop and running Ubuntu Linux on it, here’s my experience with it.

It’s been 4 months now and my experience is positive – everything works, though not from the beginning. My exact model is FX705GD-EW106T with the following specs:

  • CPU: Core i7 8750H
  • RAM: 16GB of DDR4 (now upgraded to 32GB)
  • Storage: 256GB NVMe SSD + 1TB HDD
  • GPU: GTX 1050 (switching)
  • Screen: 17,3″ Full HD IPS
  • OS: Windows 10 Home

TL;DR: Use kernel 5.3+ and everything will work.

Asus TUF Gaming FX705GD running Ubuntu 19.10
Asus TUF Gaming FX705GD running Ubuntu 19.10

I initially tried installing Ubuntu 18.04 because I prefer LTS releases, but although it installed normally, I could not boot into Ubuntu. I did not invest any time in debugging, because I already had the 19.04 image ready, so I tried installing that. It worked, I guess because of the 5.0 kernel.

With Ubuntu 19.04 and kernel 5.0 pretty much everything worked, except the keyboard backlight. For example, when waking up the laptop from sleep, it would not light up at all. Only turning off the machine and starting it again would make the backlight come back. Or it would stay on even when the screen was locked and therefore turned off.

So using the Ukuu tool I updated the kernel to 5.2 and backlight was working again when coming back from sleep – most of the time. However, the function keys to brighten or dim the backlight would still not work (there are 3 levels btw). Any press of either keys would completely turn off the backlight and again a complete power off was needed to get it back.

So some time passed and kernel 5.3 was released. It was with great joy that after installing it, I could state the laptop was fully functional – the backlight was working and so were the + and – keys.

Today (Dec 2019), after upgrading Ubuntu, I am on 19.10 which ships with kernel 5.3, so if you install this release, everything should work out of the box!

So your choice is either to use the 5.3 kernel on a pre-19.10 version or to use 19.10.

CKEditor save button callback

I am sharing this since it was impossible to find with Google.

Before CKEditor 4.2 if you wanted to handle the save event with a custom function, you had to write your own plugin.

Now all you need to do is to specify the callback upon initialization:

CKEDITOR.replace('ckeditor', {
	on: {
		save: function(evt)
		{
			// Do something here, for example:
			console.log(evt.editor.getData());

			// If you want to prevent the form submit (if your editor is in a <form> element), return false here
			return false;
		}
	}
});

jQuery YoxView “Error loading language file”

A quick note for all googlers: If you happen to stumble upon this error when using the great YoxView plugin for jQuery, make sure you don’t put the script in a folder that has “jquery.yoxview” in it’s name. There’s a bug in the script which uses a loose regular expression, which, when provided the following URL
http://example.com/js/jquery.yoxview/jquery.yoxview.2.21.min.js
will return
http://example.com/js/
and thus will try to request the language files from e.g. http://example.com/js/lang/en.js

I have the habit of unzipping the archive and using a full script name + version for the folder name, which has the benefit, that when you change the script version, all your returning visitors will definitely get the latest script since the cache for it will not exist.