22

I was calibrating my touch screen, and saw that the best tool around was xinput_calibrator. So I used it. It have two options (one of which did not work), so I am here for the second. It says I should execute this command "in a script that starts with your X session":

xinput set-int-prop "3M 3M USB Touchscreen - EX II" "Evdev Axis Calibration" 32 14410 2146 14574 2115

So I tried ~/.xinitrc, ~/.xsession and ~/.xsessionrc, all of which did not exist. So I created them and the exact content was this command. The first two files made my logins fail (after I login, I fall back to the login screen).

With the last file, the calibration was functional, but only after logging in...

I need that command to run before the login dialog shows up. I thought of adding this command to the end of /etc/X11/xinit/xinitrc with no result (nothing changed). Also, I tried to add it to the end of /etc/X11/Xsession.d/40x11-common_xsessionrc (after inspecting some of the files), but the result was exactly the same as adding it to ~/.xsessionrc.

How can I make this command run before the login screen shows (is this before the window manager starts, or before the X session starts)?

(I am running Kubuntu with the default window manager, if that matters)

UPDATE As I am using Kubuntu, my display manager is kdm. As the accepted answer suggests, I edited the file /etc/kde4/kdm/Xsetup, and as mentioned here I added the command before the command that is there by default. And it works like a charm :)

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
jadkik94
  • 983
  • 4
    What login manager are you using? For gdm3 you can probably use /etc/gdm3/Init/display or /etc/gdm3/Init/Default - http://manpages.debian.net/cgi-bin/man.cgi?query=gdm3&apropos=0&sektion=0&manpath=Debian+6.0+squeeze&format=html&locale=en – Ulrich Dangel Jul 08 '12 at 23:08
  • Hey, good stuff. I've posted a question here [http://unix.stackexchange.com/questions/172007/linux-mint-17-cinnamon-how-can-i-run-an-application-prior-to-the-login-screen] which got marked as a possible duplicate to this Q&A. However, folks, am not convinced it's a clone. Pl see my question too and help me out :) – kaiwan Dec 08 '14 at 07:36

4 Answers4

15

All the files you tried to change are read after you log in. Furthermore, ~/.xinitrc and ~/.xsession are the full set of commands that run in a session; ~/.xinitrc is read if you run xinit or startx from a text mode prompt, and ~/.xsession is read if you run a “custom session” (the name may vary) from a graphical login prompt.

You need to configure your display manager, the program that shows the login prompt. For kdm, the KDE display manager, add your command to /etc/kde4/kdm/Xsetup (or /etc/kde3/kdm/Xsetup for older versions) (that's the path on Debian, I haven't verified that Kubuntu uses the same path).

For gdm (the Gnome display manager), add your command to /etc/gdm/Init/Default. For xdm (the traditional X display manager), add your command to /etc/X11/xdm/Xsetup.

Ulrich Dangel
  • 25,369
  • Thanks for the explanation! I tried what you suggested without success. I located the Xsetup file (in the same path you mentioned) and added the command. The calibration did not work, but I made sure it was executed, by adding echo "w" > /test.log, and verifying /test.log did exist after reboot. Is it possible that xinput requires special "context" or something... ? – jadkik94 Jul 10 '12 at 21:11
  • Actually, disregard the last comment. I redirected the xinput command to that file, and it seems I had added a space to the device name which made the calibration not work. You were 100% correct :) Thanks again. – jadkik94 Jul 10 '12 at 21:19
  • 7
    And just to complete the answer - to find out what is your display manager (not to be confused with a desktop environment) use: cat /etc/X11/default-display-manager. – Nux Oct 23 '12 at 09:12
  • What about xserverrc? And the ones that are in /etc/X11/xinit/xserverrc? – CMCDragonkai Aug 26 '16 at 10:38
  • @CMCDragonkai xserverrc is executed by startx. Since it runs before the X server start (actually, its job is to start the X server), it wouldn't have been of any use here. – Gilles 'SO- stop being evil' Aug 26 '16 at 11:07
  • Doesn't the display manager itself need an X server to display anything? I feel like you're talking about having an X server after the display manager, whereas I thought the X server needs to be available before the display manager? – CMCDragonkai Aug 26 '16 at 13:16
  • 1
    @CMCDragonkai If there's a display manager, startx is not used. Display manager initialization scripts would not be relevant here since they run before the user logs in. – Gilles 'SO- stop being evil' Aug 26 '16 at 13:32
4

I suggest that you create your own config file, a simple example:

/usr/lib/X11/xorg.conf.d/20-calibration.conf

Filecontent:

Section "InputClass"
         Identifier "Calibration"
         MatchProduct "3M 3M USB Touchscreen - EX II"
         Option "Calibration" "14410 2146 14574 2115"
EndSection

That should do the trick.

ortang
  • 141
-1

You could try /etc/rc.local ?

.

amarc
  • 1
  • 4
    I was concerned the script would run before X even starts (as I understood it), which would render that script useless... When does this run? – jadkik94 Jul 08 '12 at 21:03
  • 3
    @jadkik94 you are right this won't work as rc.local doesn't have access to the x session. – Ulrich Dangel Jul 08 '12 at 23:04
-1

When you have OpenSUSE you can copy your script to /etc/init.d and run insserv script name. insserv enables a script: http://man-wiki.net/index.php/8:insserv.

Micromega
  • 4,211