Single instance applications are fun in any programming language. Let’s take QT as example. One could just create a server and depending on whether it can listen, determine if another instance is running. Something like this:
server =newQLocalServer();bool serverListening = server.listen("SomeName");if(!serverListening){//hey, I'm walkin over here}
And that’s it. Only if it would be this easy.
This code might fail on Unix with AddressInUseError if there was a previous application crash. This means we need to complicate code a bit:
server =newQLocalServer();bool serverListening = server.listen("SomeName");if(!serverListening &&(server->serverError()== QAbstractSocket::AddressInUseError)){QLocalServer::removeServer(serverName);//cleanup
serverListening = _server->listen(serverName);//try again}if(!serverListening){//hey, I'm walkin over here}
But fun wouldn’t be complete if that was all. You see, Windows have issues of their own. As implemented in QT, you can actually have multiple listeners at the same time. Failure to listen will never happen there.
Unfortunately this is a bit more complicated and you can really go wild solving this issue - even so far as to involve QSystemSemaphore with it’s portability and thread blocking issues.
Or you can go with solution that works 99% of the time - directly calling into CreateMutexW API.
Modifying code in the following manner will do the trick:
server =newQLocalServer();bool serverListening = server.listen("SomeName");if(!serverListening &&(server->serverError()== QAbstractSocket::AddressInUseError)){QLocalServer::removeServer(serverName);//cleanup
serverListening = _server->listen(serverName);//try again}#ifdefined(Q_OS_WIN)if(serverListening){CreateMutexW(nullptr,true,reinterpret_cast<LPCWSTR>(serverName.utf16()));if(GetLastError()== ERROR_ALREADY_EXISTS){//someone has this Mutex
server->close();//disable server
serverListening =false;}}#endifif(!serverListening){//hey, I'm walkin over here}
Now on Windows we try to create our very own mutex. If that succeeds, all is normal. If that returns an error, we simply close our server because we know some other instance owns the mutex.
Not ideal but it covers single-instance scenario reasonably well.
If you want to use this in application, you can download the example and use it as follows:
if(!SingleInstance::attach()){returnstatic_cast<int>(0x80004004);//exit immediately if another instance is running}
As a headphone user I find nothing more annoying than computer asking me every single freaking time what exactly did I plug in. While Windows drivers for Dell XPS 15 audio do allow you to select default, one is not so lucky under Linux.
However, Linux being configurable to a fault does offer a workaround.
You can append the following options to the end of /etc/modprobe.d/alsa-base.conf, followed by a reboot:
options snd-hda-intel model=headset-mic
This will lie a bit to sound driver and stop the darn questions.
I wanted a simple system tray application that would work on both Windows and Linux. As C# doesn’t really have a proper GUI for Linux (albeit you can come a long way using Windows Forms), I decided to go with QT.
Under Windows it worked beautifully. Under Ubuntu - not so. QT example for tray icon was pretty much equivalent and it worked flawlessly. But my simple example just wouldn’t. It took me a while but I traced the issue.
Upon click I wanted to display a context menu. It seemed innocent enough to dynamically create it:
And this works under Windows. But Ubuntu and it’s Unity GUI don’t really know what to do with tray icon without preassigned context menu. And thus tray icon is never actually displayed.
Once I figured that out, solution was simple. Just assign menu statically:
While I already wrote about expanding DropBox’s Ext4 volume on ZFS, I never actually wrote how to create one in the first place. I guess it’s time to fix that injustice.
First you need to create a volume of sufficient size. While you can just make it as big as your Dropbox allowance is, I would advise going with at least double of that. Not only this helps if you are doing ZFS snapshots (remember it’s copy-on-write) but it also helps if you are moving files around as Dropbox fully releases space only once the new files are created.
Whatever you decide, you need to create a volume and format it:
Do note the _netdev part as it ensures dropbox volume is mounted way after ZFS has already done so. Without it you might have a race condition and volume mounting might prevent subpools to be mounted under the same path.
Finally you can install Dropbox as you usually would. While it will complain about directory already being present, you can simply cancel directory selection and it will start syncing regardless.
If you try to import mp4 file to DaVinci Resolve under Linux, you will be greeted with audio-only experience if you’re lucky or nothing at all if you’re not. Unless you’re paying customer of DaVinci Resolve Studion, MP4 and AAC are not supported at all.
Conversion to an intermediate format is needed and good old ffmpeg can help here:
Here I use DNxHR with HQ settings. Even this will generate file that’s much bigger than source. How much bigger depends on the source, but don’t be surprised to see it grow 16-fold or even higher.
Smaller alternative can be MPEG4 format but with a drop in quality even at its best settings:
These files can now be used as input to Resolve and editing can commence.
Once done with rendering a conversion to MP4 might be in order again. For this I use settings discussed on Video StackExchange. While the original discussion was for YouTube, I find their recommendations quite good as a starting point:
Mind you, all my cameras use YUV 4:2:0 and I don’t do any major editing so increasing YUV to 4:2:2 or even 4:4:4 makes no sense nor does increase to 10-bit resolution. Depending on which equipment you have, your mileage may vary.