22 września, 2008
Openbox Shutdowner (mechanizm GDM, gui GTK)
Napisane w: Linux, Oprogramowanie, Skrypty (1)
Openbox od wersji 3.4.7 posiada program gdm-control, który potrafi skonfigurować tak GDM, że gdy zakończymy sesje, wykona on ustawioną mu akcję. Oczywiście jak na news przystało, ciekawe, ciekawe, ale jak u licha tego używać? Można zrobić wpisy w menu, coś na podobieństwo tego:
<item label="Wyłącz komputer"> <action name="Execute"> <execute> gdm-control --shutdown && openbox --exit </execute> </action> </item>
Szczerze? Nie podoba mnie się to! Postanowiłem napisać małą aplikacyjkę (o ile można to tak nazwać).. Moim wyborem padł gtkdialog i glade. Tak wygląda chwilka klikania (lub "mlaskania urządzeniem wskazującym" - wyborne jabłko) w glade:

a tak wygląda wygenerowany przez niego kod xml:
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<widget class="GtkWindow" id="MAIN_WINDOW">
<property name="width_request">620</property>
<property name="title">Wyłącznik openbox</property>
<property name="icon_name">application-exit</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="modal">False</property>
<property name="resizable">False</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">True</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<child>
<widget class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<property name="border_width">6</property>
<child>
<widget class="GtkButton" id="button1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="gdm-control --none"/>
<signal name="clicked" handler="openbox --exit"/>
<signal name="clicked" handler="exit:Normal"/>
<child>
<widget class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="icon_size">6</property>
<property name="pixel_size">128</property>
<property name="icon_name">system-log-out</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkButton" id="button2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="gnome-screensaver-command -l"/>
<signal name="clicked" handler="exit:system-lock-screen"/>
<child>
<widget class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="pixel_size">128</property>
<property name="icon_name">system-lock-screen</property>
</widget>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="gdm-control --reboot"/>
<signal name="clicked" handler="openbox --exit"/>
<signal name="clicked" handler="exit:Normal"/>
<child>
<widget class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="icon_size">0</property>
<property name="pixel_size">128</property>
<property name="icon_name">view-refresh</property>
</widget>
</child>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="gdm-control --shutdown"/>
<signal name="clicked" handler="openbox --exit" />
<signal name="clicked" handler="exit:Shutdown"/>
<child>
<widget class="GtkImage" id="image4">
<property name="visible">True</property>
<property name="icon_size">0</property>
<property name="pixel_size">128</property>
<property name="icon_name">system-shutdown</property>
</widget>
</child>
</widget>
<packing>
<property name="position">3</property>
</packing>
</child>
</widget>
</child>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<child>
<widget class="GtkLabel" id="Akcja">
<property name="visible">True</property>
</widget>
<packing>
<property name="padding">6</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="Anuluj">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="exit:Anuluj" />
<child>
<widget class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<child>
<widget class="GtkImage" id="Anuluj_image">
<property name="visible">True</property>
<property name="stock">gtk-cancel</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">3</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="Anuluj_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Anuluj</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
</widget>
<packing>
<property name="fill">False</property>
<property name="padding">3</property>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">6</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="padding">6</property>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>Tak to się uruchamia:
gtkdialog --glade-xml=PATHTOFILE/shutdowner.glade \ --program=MAIN_WINDOW
Prawda, że bułeczka z masłem?