How to use shortcuts to switch between displays in LXDE?
Solution 1
The idea is to use xrandr
commands. But how to find the proper commands?
I have found a simple solution as a result of this answer.
Simpler, because involves using the LXDE default display manager, LXRandr, without the need of scripts.
It can save configurations (which are xrandr configurations).
When it saves the present configuration the older one is overwritten. But finding them and using them as shortcuts is a nice way to achieve what we want here.
The save is in ~/.config/autostart/lxrandr-autostart.desktop
.
The file looks like
[Desktop Entry]
Type=Application
Name=LXRandR autostart
Comment=Start xrandr with settings done in LXRandR
Exec=xrandr --output LVDS --mode 1680x1050 --rate 60.1 --output VGA-0 --off
OnlyShowIn=LXDE
So, to save a certain configuration, open that file in a text editor like gedit
gedit ~/.config/autostart/lxrandr-autostart.desktop
and save the line after Exec=
, which is a command to be run with a shortkey.
Creating shortcuts in LXDE is presented in the other answer, that is by editing the file ~/.config/openbox/lubuntu-rc.xml
.
For example, in order to run the command above with the shortkey Ctrl-M , the edit should be like so:
<!-- Internal monitor only -->
<keybind key="C-m">
<action name="Execute">
<command>xrandr --output LVDS --mode 1680x1050 --rate 60.1 --output VGA-0 --off</command>
</action>
</keybind>
For each computer and its specific internal+external display there should be three basic configurations (internal display only, external only, and both on); and others more only in case of various resolution settings for each of these three.
I found here that in order to have extended monitor (which is outside the capabilities of LXRandr) the command should be something like
xrandr --output VGA-0 --auto --left-of LVDS
(VGA-0 and LDTS are variables, look in ~/.config/autostart/lxrandr-autostart.desktop
to see what you have, or run xrandr -q
.)
Solution 2
If you want dual monitor functionality in Lubuntu, you have limited options. The following will show you how to enable and disable dual monitors "on the fly" using ARandR as help. These directions are a bit complicated, but trust me: they are not dangerous. This is a SAFE operation.
First, get ARandR from Synaptic or by opening the terminal and pasting:
sudo apt-get install arandr
You can find your new application under Menu -> Preferences
What you see is a virtual setup of your monitor arrangement. You will almost certainly have different names for your monitor, but here is what mine looks like.
Although you haven't really done anything at this point, save this configuration.
It will automatically create a new hidden folder called .screenlayout
in your home directory. I would encourage you to not change the file location to help with later steps. I would also encourage you to use my file names as well. This one should be called single
.
Now add your second monitor. It should be hooked up to your computer at this point, of course. I added mine by scrolling through the only other monitors that allowed activation and selected it.
Position the monitors however you like. I prefer side-by-side, but you may also put one above the other. It doesn't matter which one is on the left (or the top). It's all up to you! Here's what I like:
Once you have your desired configuration, save it again. This time, name the file dual
.
The last step in this whole process is creating hotkeys to switch monitor on the fly. In the terminal type in the following:
sudo leafpad ~/.config/openbox/lubuntu-rc.xml
Scroll down to a place where you begin to see a lot of words that say <keybind>
. You don't need to know what's happening here. Simply find a place after a </keybind>
, but before the next <keybind>
and paste the following:
<keybind key="W-2">
<action name="Execute">
<command>sh ~/.screenlayout/dual.sh</command>
</action>
</keybind>
<keybind key="W-1">
<action name="Execute">
<command>sh ~/.screenlayout/single.sh</command>
</action>
</keybind>
Your code should look a little like this:
Save. Close. Logout.
If you did everything right, you should be able to press Super+2 to activate dual monitor mode. To go back to one monitor, such as your laptop, press Super+1.
One final note about the lxde panel. When I switched into dual mode, my panel looked a little funny. If you experience this problem, open up your files you created with ARandR in the .screenlayout
directory. Add the following lines to the bottom of the files:
lxpanelctl restart
Check out this page I wrote up a few months back.
Good luck.
Related videos on Youtube
Will Buck
Updated on September 18, 2022Comments
-
Will Buck over 1 year
tl:dr; This is a bit involved of a problem, any advice is welcome, appreciate reading in advance :)
My coworkers and I have been struggling a bit with an odd behavior in our batch processing application. We recently upgraded it from Grails 1.3.7 to 2.1
The stacktrace is showing the following error:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert the value NULL into column 'date_created', table 'dev.dbo.notification_log'; column does not allow nulls. INSERT fails. ... [quartzScheduler_Worker-1] [||] ERROR hibernate.AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session) org.hibernate.AssertionFailure: null id in com.virtuwell.domain.NotificationLog entry (don't flush the Session after an exception occurs) at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1891) at org.quartz.core.JobRunShell.notifyJobListenersComplete(JobRunShell.java:352) at org.quartz.core.JobRunShell.run(JobRunShell.java:223) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:546) [quartzScheduler_Worker-1] [||] ERROR listeners.SessionBinderJobListener - Cannot flush Hibernate Sesssion, error will be ignored org.hibernate.AssertionFailure: null id in com.virtuwell.domain.NotificationLog entry (don't flush the Session after an exception occurs) at org.quartz.core.QuartzScheduler.notifyJobListenersWasExecuted(QuartzScheduler.java:1891) at org.quartz.core.JobRunShell.notifyJobListenersComplete(JobRunShell.java:352) at org.quartz.core.JobRunShell.run(JobRunShell.java:223) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:546)
Here is the code of that particular Domain Object (NotificationLog)
class NotificationLog implements Serializable{ Date dateCreated Notification notification NotificationDeliveryState deliveryState String message static mapping = { message type: 'text' } }
What's strange, however, is this error doesn't occur EVERY time that domain object is persisted, and we only have one place in the code that object is ever persisted, shown below:
class NotificationLogService { boolean transactional = true def logNotification(Notification notification, message, deliveryState) { def notificationLog = new NotificationLog( notification: notification, deliveryState: deliveryState, message:message ) try{ notificationLog.save(failOnError:true) } catch (Exception e) { // Failure to save a notificationLog should not rollback the calling transaction log.error "NotificationLog State:[$deliveryState] for notification:${notification?.id} did not save. Errors: ${notificationLog?.errors}, Message:$message", e } } }
We've found a 'hack' of a workaround in the below SO question where we are no longer periodically seeing the error in the logs, by adding this to the Domain Object
static mapping = { autoTimestamp true }
But this isn't the only domain we're seeing with the SAME periodic failure to save (thus, I need to add the mapping to other domains), and if this truly is necessary for
dateCreated
to function properly in Grails 2.1, I need to add it to a LOT more domains!Worse, I can't reproduce it in a Unit or Integration test, its only happening on our running Dev and QA instances.
So, 2 Questions:
Does anyone know why this error might be periodically occurring?
If not, is there a way I can globally add this
autoTimestamp true
mapping to ALL of my project's domain objects (I've been unable to find documentation for how to add it at all, other than to set it tofalse
)
Relevant SO Question: dateCreated, lastUpdated fields in Grails 2.0
Relevant Grails Maillist discussion http://grails.1312388.n4.nabble.com/dateCreated-lastUpdated-in-Grails-2-0-td4337894.html
Relevant Grails docs on autoTimestamp GORM properties http://grails.org/doc/latest/guide/GORM.html#eventsAutoTimestamping
-
Carlo Felicione almost 12 yearsI wish I could post pictures straight into the post, but I don't have enough "cred" I guess... Sorry.
-
Admin almost 12 yearsIt is possible to have a third option in which the second monitor is the only one active. That should be accessed with a third keyboard shortcut. In each case you can also save the resolution for the respective monitors. - Adding also 'lxpanelctl restart' is necessary.
-
Admin almost 12 yearsIt is your answer and you can change it as you like (in fact I was not permitted to correct the final part - a space missing between final phrases - as the edit would have been too short: maybe you can.)
-
Will Buck about 11 yearsI have not tried that. I assume that it would work as well as the
mapping
addition I demonstrated, but there are two problems with that solution: 1) GORM should already be doing that for me, and does occasionally, and 2) If I were to fix my other failing domain saves, I'd need to find a LOT of places where those domains are persisted and apply this fix, which would be very tedious, and error-prone! Appreciate your suggestion though! -
Will Buck about 11 yearsThank you so much for the second answer! I'm not sure I understand your answer to the first question though, could you clarify what you mean by 'We know the behavior is perennial'? Is this something that happens every year in grails as a whole? Or did you mean 'periodical' or 'intermittent', as in I know it isn't consistent and therefore need to start with the 'Last Resort' solution and work from there?
-
dmahapatro about 11 yearsSorry for the misunderstanding. I mingled something else in my response. See my edit now. I can try to test the same if required.
-
ChanganAuto over 2 yearsLubuntu 21.10 runs LXQt, not LXDE.