Gnome – How to Switch into Tablet Mode in Gnome

gnomekeyboardlaptoponscreen-keyboardtablet

I have a 2-in-1 laptop, where the screen flips a full 360 degrees to turn into a tablet (I have the Lenovo Yoga 3 Pro, but there are many similar devices now). I'm running Ubuntu GNOME (15.10, but I updated to GNOME 3.18 to get autorotate and auto screen dimming working), and have gotten most of the kinks worked out, but can't find a way to turn it into a fully functional tablet.

Problem 1

An onscreen keyboard will only pop up in some GNOME-specific UI components, like when searching in the activities interface, or logging in. I enabled the Screen Keyboard from accessibility options, but it doesn't seem to affect anything.

Problem 2

The next bit is disabling the main keyboard. Ideally this would happen automatically when rotating the screen past the 180 degree mark, but I would settle for a button in the top panel that disables the keyboard. Even a keyboard shortcut would work as long as there's a way to re-enable the keyboard afterward.

I'm having a hard time finding any info about:

(A) inspecting the lid sensor(s)
(B) disabling the keyboard in any way
(C) detecting when you're in an input
(D) enabling an onscreen keyboard.

If there's not already a solution out there, I could probably hack something together if there's a way to do some combination of those, especially B (at least through the command line) and D.

Best Answer

I am suffering at prolem 1 as well but there is the plugin called 'Slide for Keyboard' available and this solves the problem partially. If activated, this plugin causes the keyboard to appear when doing an edge slide from the bottom of the screen. Here is the link: https://extensions.gnome.org/extension/993/slide-for-keyboard/

You may want another keyboard layout for vertical view. You can define your own keyboard layout using XML for that. Take a look at the directory /usr/share/caribou/layouts

Use the same XML Syntax as in some already existing layouts. I use a German layout and my config for vertical keyboard looks like this:

<?xml version="1.0"?>
<layout xmlns:xi="http://www.w3.org/2001/XInclude">
  <level mode="default" name="level1" xml:base="common/qwerty.xml">
    <row>
      <key name="Escape"/>
      <key name="q"/>
      <key name="w"/>
      <key name="e">
        <key name="e"/>
        <key name="egrave"/>
        <key name="eacute"/>
        <key name="ecircumflex"/>
        <key name="ediaeresis"/>
        <key name="emacron"/>
      </key>
      <key name="r"/>
      <key name="t"/>
      <key name="z"/>
      <key name="u">
        <key name="u"/>
        <key name="ugrave"/>
        <key name="uacute"/>
        <key name="ucircumflex"/>
        <key name="udiaeresis"/>
        <key name="umacron"/>
      </key>
      <key name="i">
        <key name="i"/>
        <key name="igrave"/>
        <key name="iacute"/>
        <key name="icircumflex"/>
        <key name="idiaeresis"/>
        <key name="imacron"/>
      </key>
      <key name="o">
        <key name="o"/>
        <key name="ograve"/>
        <key name="oacute"/>
        <key name="ocircumflex"/>
        <key name="odiaeresis"/>
        <key name="omacron"/>
      </key>
      <key name="p"/>
      <key name="BackSpace" repeatable="yes"/>
    </row>
    <row align="right">
      <key name="Tab" width="1.5"/>
      <key name="a">
        <key name="a"/>
        <key name="agrave"/>
        <key name="aacute"/>
        <key name="acircumflex"/>
        <key name="adiaeresis"/>
        <key name="aring"/>
        <key name="atilde"/>
        <key name="ae"/>
        <key name="amacron"/>
      </key>
      <key name="s"/>
      <key name="d"/>
      <key name="f"/>
      <key name="g"/>
      <key name="h"/>
      <key name="j"/>
      <key name="k"/>
      <key name="l"/>
      <key name="Return" width="1.5"/>
    </row>
    <row>
      <key name="Caribou_ShiftUp" toggle="level2" width="1.5"/>
      <key name="y"/>
      <key name="x"/>
      <key name="c">
        <key name="c"/>
        <key name="ccedilla"/>
      </key>
      <key name="v"/>
      <key name="b"/>
      <key name="n"/>
      <key name="m"/>
      <key name="comma"/>
      <key name="period"/>
      <key name="question"/>
    </row>
    <row>
      <key align="left" name="Caribou_Symbols" toggle="symbols1" width="2.0"/>
      <key align="left" name="Control_L" width="1.5"/>
      <key align="left" name="Alt_L" width="1.5"/>
      <key align="left" name="space" width="5.0" repeatable="yes"/>
      <key align="right" name="Caribou_Prefs"/>
    </row>
  </level>
  <level mode="latched" name="level2" xml:base="common/qwerty.xml">
    <row>
      <key name="Escape"/>
      <key name="Q"/>
      <key name="W"/>
      <key name="E">
        <key name="E"/>
        <key name="Egrave"/>
        <key name="Eacute"/>
        <key name="Ecircumflex"/>
        <key name="Ediaeresis"/>
        <key name="Emacron"/>
      </key>
      <key name="R"/>
      <key name="T"/>
      <key name="Z"/>
      <key name="U">
        <key name="U"/>
        <key name="Ugrave"/>
        <key name="Uacute"/>
        <key name="Ucircumflex"/>
        <key name="Udiaeresis"/>
        <key name="Umacron"/>
      </key>
      <key name="I">
        <key name="I"/>
        <key name="Igrave"/>
        <key name="Iacute"/>
        <key name="Icircumflex"/>
        <key name="Idiaeresis"/>
        <key name="Imacron"/>
      </key>
      <key name="O">
        <key name="O"/>
        <key name="Ograve"/>
        <key name="Oacute"/>
        <key name="Ocircumflex"/>
        <key name="Odiaeresis"/>
        <key name="Omacron"/>
      </key>
      <key name="P"/>
      <key name="BackSpace" repeatable="yes"/>
    </row>
    <row align="right">
      <key name="Tab" width="1.5"/>
      <key name="A">
        <key name="A"/>
        <key name="Agrave"/>
        <key name="Aacute"/>
        <key name="Acircumflex"/>
        <key name="Adiaeresis"/>
        <key name="Aring"/>
        <key name="Atilde"/>
        <key name="Ae"/>
        <key name="Amacron"/>
      </key>
      <key name="S"/>
      <key name="D"/>
      <key name="F"/>
      <key name="G"/>
      <key name="H"/>
      <key name="J"/>
      <key name="K"/>
      <key name="L"/>
      <key name="Return" width="1.5"/>
    </row>
    <row>
      <key name="Caribou_ShiftDown" toggle="level1" width="1.5"/>
      <key name="Y"/>
      <key name="X"/>
      <key name="C">
        <key name="C"/>
        <key name="Ccedilla"/>
      </key>
      <key name="V"/>
      <key name="B"/>
      <key name="N"/>
      <key name="M"/>
      <key name="comma"/>
      <key name="period"/>
      <key name="question"/>
    </row>
    <row>
      <key align="left" name="Caribou_Symbols" toggle="symbols1" width="2.0"/>
      <key align="left" name="Control_L" width="1.5"/>
      <key align="left" name="Alt_L" width="1.5"/>
      <key align="left" name="space" width="5.0" repeatable="yes"/>
      <key align="right" name="Caribou_Prefs"/>
    </row>
  </level>
  <level mode="locked" name="symbols1" xml:base="common/symbols.xml">
    <row>
      <key name="Escape"/>
      <key name="1"/>
      <key name="2"/>
      <key name="3"/>
      <key name="4"/>
      <key name="5"/>
      <key name="6"/>
      <key name="7"/>
      <key name="8"/>
      <key name="9"/>
      <key name="0"/>
      <key name="BackSpace" repeatable="yes"/>
    </row>
    <row align="right">
      <key name="Tab" width="1.5"/>
      <key name="minus"/>
      <key name="slash"/>
      <key name="colon"/>
      <key name="semicolon"/>
      <key name="parenleft"/>
      <key name="parenright"/>
      <key name="ampersand"/>
      <key name="at"/>
      <key name="grave"/>
      <key name="Return" width="1.5"/>
    </row>
    <row>
      <key name="Caribou_Symbols_More" toggle="symbols2" width="2.0"/>
      <key name="period" width="1.2"/>
      <key name="comma" width="1.2"/>
      <key name="question" width="1.2">
        <key name="question"/>
        <key name="questiondown"/>
      </key>
      <key name="exclam" width="1.2">
        <key name="exclam"/>
        <key name="exclamdown"/>
      </key>
      <key name="apostrophe" width="1.2"/>
      <key name="quotedbl" width="1.2"/>
    </row>
    <row>
      <key align="left" name="Caribou_Alpha" toggle="default" width="2.0"/>
      <key align="left" name="Control_L" width="1.5"/>
      <key align="left" name="Alt_L" width="1.5"/>
      <key align="left" name="space" width="5.0" repeatable="yes"/>
      <key align="right" name="Caribou_Prefs"/>
    </row>
  </level>
  <level mode="locked" name="symbols2" xml:base="common/symbols.xml">
    <row>
      <key name="Escape"/>
      <key name="bracketleft"/>
      <key name="bracketright"/>
      <key name="braceleft"/>
      <key name="braceright"/>
      <key name="numbersign"/>
      <key name="percent"/>
      <key name="asciicircum"/>
      <key name="asterisk"/>
      <key name="plus"/>
      <key name="equal"/>
      <key name="BackSpace" repeatable="yes"/>
    </row>
    <row align="right">
      <key name="Tab" width="1.5"/>
      <key align="right" name="underscore"/>
      <key name="backslash"/>
      <key name="bar"/>
      <key name="asciitilde"/>
      <key name="less"/>
      <key name="greater"/>
      <key name="dollar"/>
      <key name="EuroSign"/>
      <key name="sterling"/>
      <key name="Return" width="1.5"/>
    </row>
    <row>
      <key name="Caribou_Symbols" toggle="symbols1" width="2.0"/>
      <key name="period" width="1.2"/>
      <key name="comma" width="1.2"/>
      <key name="question" width="1.2">
        <key name="question"/>
        <key name="questiondown"/>
      </key>
      <key name="exclam" width="1.2">
        <key name="exclam"/>
        <key name="exclamdown"/>
      </key>
      <key name="apostrophe" width="1.2"/>
      <key name="quotedbl" width="1.2"/>
    </row>
    <row>
      <key align="left" name="Caribou_Alpha" toggle="default" width="2.0"/>
      <key align="left" name="Control_L" width="1.5"/>
      <key align="left" name="Alt_L" width="1.5"/>
      <key align="left" name="space" width="5.0" repeatable="yes"/>
      <key align="right" name="Caribou_Prefs"/>
    </row>
  </level>
</layout>

I just removed a few mostly unused keys.

Then trigger the following script on vertical (left or right) rotation:

gsettings set org.gnome.shell.keyboard keyboard-type <your-keyboard-layout-name>

And trigger the same script with the normal layout for normal and inverted rotation.

For problem 2, write a script to toggle the keyboard first. The script shall look like this:

#!/bin/bash
device='AT Translated Set 2 keyboard'
oldstate=$(xinput list-props "$device" | grep 'Device Enabled' | rev | cut -b 1)
newstate=1
if [ "$oldstate" = "1" ]; then
    newstate=0;
fi
xinput set-prop "$device" 'Device Enabled' "$newstate"

While 'AT Translated Set 2 keyboard' is the name of the keyboard. Yours might have a similar name. Search for it with the command

xinput list | grep keyboard

and try to disable and reenable the printed devices. (Install 'Slide for Keyboard' first so you're still able to type in the command line)

You should put this script either on a hotkey or as a launcher in your applications list because you might not be able to reenable the keyboard if the script is on a keyboard shortcut.

Related Question