Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Desktop Environments
  • Search

How to run at command before kdm starts up.

Problems with GUI applications? Questions about X, KDE, Gnome, Fluxbox, etc.? Come on in. NOTE: For multimedia, go up one forum
Post Reply
Advanced search
7 posts • Page 1 of 1
Author
Message
schiotz
Apprentice
Apprentice
Posts: 206
Joined: Tue Jan 20, 2004 1:58 pm
Location: Denmark

How to run at command before kdm starts up.

  • Quote

Post by schiotz » Thu Jul 17, 2008 9:36 am

Hi gurus!

I want to run a script before kdm starts up (or, if that is not possible, right after).

Basically, I have written a script that checks if my laptop is connected to an external flatscreen, and if so it disables the internal panel (using xrandr). In that way I get the right resolution on the external screen (it is 1280x1024, the panel is 1400x1050).

How do I get the script to run when X starts up?

Any help is appreciated.

/Jakob
Top
aceFruchtsaft
Guru
Guru
User avatar
Posts: 438
Joined: Sun May 16, 2004 12:56 pm
Location: Vienna, Austria

  • Quote

Post by aceFruchtsaft » Thu Jul 17, 2008 9:47 am

If you don't mind the script being executed only after you log in, you can always use ~/.xinitc or place a script into ~/.kde/Autostart.
Top
schiotz
Apprentice
Apprentice
Posts: 206
Joined: Tue Jan 20, 2004 1:58 pm
Location: Denmark

  • Quote

Post by schiotz » Thu Jul 17, 2008 10:33 am

aceFruchtsaft wrote:If you don't mind the script being executed only after you log in, you can always use ~/.xinitc or place a script into ~/.kde/Autostart.
Well, that will be an acceptable workaround. But then the screen resolution etc has been set, and the fonts are adapted to the wrong panel (I get rather large letters). But until I find something better, I will follow your suggestion.

/Jakob
Top
vorgas
n00b
n00b
Posts: 48
Joined: Wed Nov 02, 2005 3:55 pm

A few alternatives

  • Quote

Post by vorgas » Thu Jul 17, 2008 1:46 pm

The best thing to do is put the command in /etc/conf.d/local.start. You may or may not want to use the "&" at the end of the line to background the process. Depends on your script and the speed of your computer.

If you really need X to start first, then put a few lines at the top of your script like:

Code: Select all

c=0
while [ ! $c == 1 ]
do
c=`ps -A | grep -c X`
done
In this case, you will certainly want an "&" at the end of the local.start line.

Another option is to fire up your favorite editor as root and open /etc/init.d/xdm. Find the line that says "/etc/X11/startDM.sh". It's in the "start()" function. Just before that line, run your command. Save and exit.
Top
schiotz
Apprentice
Apprentice
Posts: 206
Joined: Tue Jan 20, 2004 1:58 pm
Location: Denmark

  • Quote

Post by schiotz » Fri Jul 18, 2008 8:53 am

Thanks for your suggestion! Unfortunately, the local.start method does not work as xrand cannot connect to the display, although I had set DISPLAY to :0. The usual X security measures get in the way.

Adding the script to startDM.sh did not work either, as X is not yet up and running.

So far, I have put it in .kde/Autostart, it is not optimal, but it sort of works. Thanks to both of you for your suggestions!

/Jakob
Top
mirekm
Apprentice
Apprentice
User avatar
Posts: 237
Joined: Thu Feb 12, 2004 8:17 am
Location: Gliwice

  • Quote

Post by mirekm » Sat Jul 19, 2008 11:58 am

You can of cours put call to your script inside of:
/usr/kde/3.5/share/confg/kdm/Xsetup

which is called as root befor login dialog appears
or inside of:nstallation of kdm
/usr/kde/3.5/share/confg/kdm/Xstartup

which is called as root after user login

or inside of:
/usr/kde/3.5/share/confg/kdm/Xsession

which is called as user after user login

Of course you must remember to update of these files after each installation of kdm
Top
schiotz
Apprentice
Apprentice
Posts: 206
Joined: Tue Jan 20, 2004 1:58 pm
Location: Denmark

  • Quote

Post by schiotz » Mon Jul 21, 2008 11:09 am

Thank you, Mirekm!

I added it to /usr/kde/3.5/share/config/kdm/Xsetup, and now the screen resolution is correct as soon as kdm starts. The fonts are unfortunately still chosen for the panel until I login and out again, but I can live with that.

In case anyone has a similar need: Here is the script I use for selecting the output. I call it as toggle-video.py --sane from Xsetup. Without --sane, it is supposed to turn an external display on or off (for presentations), but I have not yet had the chance to test that part.

Code: Select all

#!/usr/bin/python

import sys
import os
import commands
from syslog import syslog, openlog

def get_output_state(line):
    words = line.split()
    if words[1] == "disconnected":
        conn = False
    elif  words[1] == "connected":
        conn = True
    else:
        syslog("Cannot parse line: " + line)
        sys.exit(1)
    active = (len(words) > 2)
    return (words[0], conn, active)

def activate(device):
    syslog('Activating output device '+device)
    cmd = 'xrandr --output '+device+' --auto'
    (stat, info) = commands.getstatusoutput(cmd)
    if stat:
        syslog("Activating %s failed:" % (device,))
        syslog(info)
        sys.exit(1)

def deactivate(device):
    syslog('Deactivating output device '+device)
    cmd = 'xrandr --output '+device+' --off'
    (stat, info) = commands.getstatusoutput(cmd)
    if stat:
        syslog("Deactivating %s failed:" % (device,))
        syslog(info)
        sys.exit(1)




# Write to syslog under the script name
openlog(os.path.basename(sys.argv[0]))

sanearg = False
if (len(sys.argv) >= 2):
    sanearg = (sys.argv[1] == '--sane')
    if not sanearg:
        syslog("Unknown command line argument.")
        print >> sys.stderr, "Unknown command line argument."
        sys.exit(1)

query = 'xrandr -q'
(stat, info) = commands.getstatusoutput(query)
if stat:
    syslog('Command failed: '+query)
    syslog(info)
    sys.exit(1)

connected = {}
turnedon = {}

for line in info.split('\n'):
    if line.startswith('Screen 0:'):
        pass
    elif line.startswith('Screen'):
        syslog('Giving up: xrandr reports more than one screen: '+line)
        sys.exit(1)
    elif line.startswith('VGA'):
        (name, conn, on) = get_output_state(line)
        projector = name
        connected[name] = conn
        turnedon[name] = on
    elif line.startswith('DVI'):
        (name, conn, on) = get_output_state(line)
        extscreen = name
        connected[name] = conn
        turnedon[name] = on
    elif line.startswith('PANEL'):
        (name, conn, on) = get_output_state(line)
        panel = name
        connected[name] = conn
        turnedon[name] = on
    elif line.startswith(' '):
        pass
    else:
        syslog('Giving up: unknown line from xrandr: '+line)
        sys.exit(1)

syslog("Projector:    Connected: %s  Active: %s" % (connected[projector],
                                                    turnedon[projector]))
syslog("Ext. display: Connected: %s  Active: %s" % (connected[extscreen],
                                                    turnedon[extscreen]))
syslog("Panel:        Connected: %s  Active: %s" % (connected[panel],
                                                    turnedon[panel]))

if (sanearg):
    # Set a sane system: ext. screen if connected, otherwise panel
    if connected[extscreen]:
        if not turnedon[extscreen]:
            activate(extscreen)
        if turnedon[panel]:
            deactivate(panel)
    if connected[projector] and not turnedon[projector]:
        activate(projector)
else:
    # Toggle projector if connected
    if connected[extscreen] and turnedon[extscreen]:
        normal = extscreen
    else:
        normal = panel
    
    if connected[projector]:
        # Cycle throug (normal) -> (normal+projector) -> (projector)
        if turnedon[normal] and not turnedon[projector]:
            activate(projector)
        elif turnedon[normal] and turnedon[projector]:
            deactivate(normal)
        else:
            # Presumably only the projector is active, but who knows...
            if not turnedon[normal]:
                activate(normal)
            if turnedon[projector]:
                deactivate(projector)
    else:
        # Connector is not connected.  Turn on ext. screen or panel
        if connected[extscreen]:
            if not turnedon[extscreen]:
                activate(extscreen)
            if turnedon[panel]:
                deactivate(panel)
        else:
            if not turnedon[panel]:
                activate(panel)
        if turnedon[projector]:
            deactivate(projector)

Top
Post Reply

7 posts • Page 1 of 1

Return to “Desktop Environments”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic