summaryrefslogtreecommitdiffstats
path: root/tools/aewm-drakx/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aewm-drakx/client.c')
-rw-r--r--tools/aewm-drakx/client.c122
1 files changed, 0 insertions, 122 deletions
diff --git a/tools/aewm-drakx/client.c b/tools/aewm-drakx/client.c
deleted file mode 100644
index 8db6b2151..000000000
--- a/tools/aewm-drakx/client.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/* aewm - a minimalistic X11 window manager. ------- vim:sw=4:et
- * Copyright (c) 1998-2001 Decklin Foster <decklin@red-bean.com>
- * Free software! Please see README for details and license. */
-
-#include "aewm.h"
-#include <X11/Xmd.h>
-
-
-Client *head_client = NULL;
-
-Client *find_client(Window w)
-{
- Client *c;
-
- for (c = head_client; c; c = c->next)
- if (c->window == w) return c;
-
- return NULL;
-}
-
-void set_focus_on(Window w)
-{
- char *name;
- XFetchName(dpy, w, &name);
- if (name && strcmp(name, "skip")) {
- XSetInputFocus(dpy, w, RevertToPointerRoot, CurrentTime);
-#ifdef DEBUG
- printf("aewm-drakx: adding %lx %s\n", w, name);
-#endif
- }
-}
-
-/* Attempt to follow the ICCCM by explicity specifying 32 bits for
- * this property. Does this goof up on 64 bit systems? */
-void set_wm_state(Client *c, int state)
-{
- CARD32 data[2];
-
- data[0] = state;
- data[1] = None; /* Icon? We don't need no steenking icon. */
-
- XChangeProperty(dpy, c->window, wm_state, wm_state,
- 32, PropModeReplace, (unsigned char *)data, 2);
-}
-
-/* If we can't find a WM_STATE we're going to have to assume
- * Withdrawn. This is not exactly optimal, since we can't really
- * distinguish between the case where no WM has run yet and when the
- * state was explicitly removed (Clients are allowed to either set the
- * atom to Withdrawn or just remove it... yuck.) */
-long get_wm_state(Client *c)
-{
- Atom real_type; int real_format;
- unsigned long items_read, items_left;
- long *data, state = WithdrawnState;
-
- if (XGetWindowProperty(dpy, c->window, wm_state, 0L, 2L, False,
- wm_state, &real_type, &real_format, &items_read, &items_left,
- (unsigned char **) &data) == Success && items_read) {
- state = *data;
- XFree(data);
- }
- return state;
-}
-
-void remove_client(Client *c)
-{
- int ignore_xerror(Display *dpy, XErrorEvent *e) { return 0; }
-
- Client *p;
-
- XGrabServer(dpy);
- XSetErrorHandler(ignore_xerror);
-
- set_wm_state(c, WithdrawnState);
-
- if (head_client == c) head_client = c->next;
- else for (p = head_client; p && p->next; p = p->next)
- if (p->next == c) p->next = c->next;
-
- free(c);
-
- if (head_client) set_focus_on(head_client->window);
-
- XSync(dpy, False);
- XSetErrorHandler(handle_xerror);
- XUngrabServer(dpy);
-}
-
-void make_new_client(Window w)
-{
- Client *c;
- XWindowAttributes attr;
-
- c = malloc(sizeof *c);
- c->next = head_client;
- c->window = w;
- head_client = c;
-
- XGrabServer(dpy);
- XGetWindowAttributes(dpy, w, &attr);
-
-
- if (attr.map_state != IsViewable) {
- XWMHints *hints;
- set_wm_state(c, NormalState);
- if ((hints = XGetWMHints(dpy, w))) {
- if (hints->flags & StateHint) set_wm_state(c, hints->initial_state);
- XFree(hints);
- }
- }
- if (attr.map_state == IsViewable) {
- XMapWindow(dpy, c->window);
- set_wm_state(c, NormalState);
- } else if (get_wm_state(c) == NormalState) {
- XMapWindow(dpy, c->window);
- }
- set_focus_on(w);
-
- XSync(dpy, False);
- XUngrabServer(dpy);
-}
279' href='#n279'>279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
#!/usr/bin/perl

# DrakBoot
# $Id$
# Copyright (C) 2001-2008 Mandriva
# Yves Duret, Thierry Vignaud
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

use strict;
use diagnostics;
use lib qw(/usr/lib/libDrakX);

use standalone; #- warning, standalone must be loaded very first, for 'explanations'
use c;
use common;
use interactive;
use any;
use bootloader;
use fsedit;
use fs;
use Config;
use POSIX;
use Xconfig::various;
use log;

my $in = 'interactive'->vnew('su');

my $all_hds;
my $fstab;
my $bootloader;
my $cmdline = cat_('/proc/cmdline');

my $is_bootloader_mode = !$in->isa('interactive::gtk') || any { /^--boot$/ } @ARGV;

if ($is_bootloader_mode || any { /^--splash$/ } @ARGV) {
    $all_hds = fsedit::get_hds();
    fs::get_raw_hds('', $all_hds);
    fs::get_info_from_fstab($all_hds);
    $fstab = [ fs::get::fstab($all_hds) ];
    $bootloader = bootloader::read($all_hds);
    if (!$bootloader) {
        $in->ask_okcancel('', N("No bootloader found, creating a new configuration"), 0) or $in->exit;
        any::setupBootloaderBeforeStandalone($in->do_pkgs, $bootloader ||= {}, $all_hds, $fstab);
    }
}

if ($is_bootloader_mode) {
    $::isWizard = 1;
    eval { any::setupBootloaderUntilInstalled($in, $bootloader, $all_hds, $fstab, $ENV{SECURE_LEVEL}) };
    die if $@ && $@ !~ /^wizcancel/;
    $in->exit(0);
}

require ugtk2;
ugtk2->import(qw(:helpers :wrappers :create));
require mygtk2;
mygtk2->import(qw(gtknew));

if (any { /^--splash$/ } @ARGV) {
    splash_choice();
} else {
    autologin_choice();
}

sub run_boot_window {
    my ($title, $pack_list, $apply_sub) = @_;

    my $w = ugtk2->new($title);
    my $window = $w->{window};
    $::main_window = $w->{real_window};

    $window->signal_connect(delete_event => sub { ugtk2->exit(0) });
    unless ($::isEmbedded) {
        $window->set_border_width(2);
        ### menus definition
        # the menus are not shown but they provides shiny shortcut like C-q
        my @menu_items = ([ N("/_File"), undef, undef, undef, '<Branch>' ],
                          [ N("/File/_Quit"), N("<control>Q"), sub { ugtk2->exit(0) }, undef, '<Item>' ],
                         );
        create_factory_menu($w->{rwindow}, @menu_items);
        ######### menus end
    }
    gtkadd($window, gtknew('VBox', children => [
                             @$pack_list,
                             0, create_okcancel({
                                                 cancel_clicked => sub { ugtk2->exit(0) },
                                                 ok_clicked => sub {
                                                     $apply_sub->();
                                                     ugtk2->exit(0);
                                                 }
                                                }) ]));
    $window->show_all;
    gtkflush();
    $w->main;
    $in->exit(0);
}

sub splash_choice() {
    require bootsplash;
    my ($cur_res, $bootsplash_available) = bootsplash::get_framebuffer_resolution();
    $bootsplash_available = 1 if $::testing;

    my $theme = bootsplash::themes_read_sysconfig($cur_res);
    $bootsplash_available or $theme->{enabled} = 0;

    my $boot_pic = gtknew('Image', file => $bootsplash::default_thumbnail);
    change_image($boot_pic, $theme->{name}, $cur_res);

    my $theme_combo = gtknew('ComboBox', text => $theme->{name}, list => [ bootsplash::themes_list_for_resolution($cur_res) ]);
    $theme_combo->entry->signal_connect(changed => sub {
                                            $theme->{name} = $theme_combo->entry->get_text;
                                            change_image($boot_pic, $theme->{name}, $cur_res);
                                        });

    my $splash_box;
    my $boot_warn = 1;
    my %modes = (
		 text => N("Text only"),
		 verbose => N("Verbose"),
		 silent => N("Silent"),
		);
    my $mode_combo = gtknew('ComboBox', text => $modes{$theme->{enabled} ? $cmdline =~ /\bsplash=silent\b/ ? 'silent' : 'verbose' : 'text'}, list => [ values %modes  ]);
    $mode_combo->entry->signal_connect(changed => sub {
					    $theme->{enabled} = $mode_combo->entry->get_text ne $modes{text};
					    if ($boot_warn && !$bootsplash_available && $theme->{enabled}) {
						if ($in->ask_yesorno(N("Warning"),
								     [ N("Your system bootloader is not in framebuffer mode. To activate graphical boot, select a graphic video mode from the bootloader configuration tool.") . "\n" .
								       N("Do you want to configure it now?") ])) {
						    enable_framebuffer();
						    #- it would be nice to get available themes for new cur_res here
						}
						$boot_warn = 0;
					    }
					    $splash_box->set_sensitive($theme->{enabled});
					});

    my $_thm_button = gtknew('Button', text => N("Install themes"));

    run_boot_window(N("Graphical boot theme selection"),
                       [
                        1, gtknew('VBox', spacing => 5, border_width => 5, children => [
				    0, gtknew('HBox', spacing => 5, children_tight => [ gtknew('Label', text => N("Graphical boot mode:")), $mode_combo ]),
				    0, $splash_box = gtknew('HBox', sensitive => $theme->{enabled}, children_loose => [
					       gtkadd(gtkcreate_frame(N("Theme")),
						      gtknew('VBox', spacing => 5, children_tight => [
								$theme_combo,
								gtksignal_connect(gtkset_active(gtknew('CheckButton', text => N("Display theme\nunder console")),
												$theme->{keep_logo}),
										  clicked => sub { invbool(\$theme->{keep_logo}) }) ])),
					       gtknew('VSeparator'),
					       gtknew('VBox', spacing => 5, children_tight => [ $boot_pic ]) ]),
				    0, gtknew('Button', text => N("Create new theme"), clicked => sub { exec '/usr/sbin/draksplash' }) ]),
                       ],
                       sub {
                           bootsplash::set_logo_console($theme->{keep_logo});
                           if ($theme->{enabled}) {
                               bootsplash::switch($theme->{name});
                           } else {
                               bootsplash::remove();
                           }
			   my $text = $mode_combo->entry->get_text;
			   my $mode = find { $modes{$_} eq $text } keys %modes;
			   set_splash_append($mode ne 'text' ? $mode : undef);
                       });
}

sub autologin_choice() {
    my @users = sort(list_users());
    my @sessions = sort(split(' ', `/usr/sbin/chksession -l`));

    my $x_mode = Xconfig::various::runlevel() == 5;
    my $auto_mode = any::get_autologin();

    my $user = member($auto_mode->{user}, @users) ? $auto_mode->{user} : $users[0];
    if (!$user) {
        # no user, bad but add root anyway:
        $user = "root";
        push @users, $user;
    }
    my $user_combo = gtknew('ComboBox', text => $user, list => \@users);
    my $desktop_combo = Gtk2::ComboBox->new_with_strings(\@sessions, if_(member($auto_mode->{desktop}, @sessions), $auto_mode->{desktop}));

    my $auto_box = gtknew('Table', col_spacings => 5, row_spacings => 5, homogeneous => 1, children => [
                                    [ gtknew('Label_Left', text => N("Default user")), $user_combo ],
                                    [ gtknew('Label_Left', text => N("Default desktop")), $desktop_combo ] ]);
    $auto_box->set_sensitive($auto_mode->{user} ? 1 : 0);

    my @auto_buttons = gtkradio((N("No, I do not want autologin")) x 2,
                                N("Yes, I want autologin with this (user, desktop)"));
    $auto_buttons[1]->signal_connect('toggled' => sub { $auto_box->set_sensitive($auto_buttons[1]->get_active) });
    $auto_buttons[0]->signal_connect('toggled' => sub { $auto_box->set_sensitive(!$auto_buttons[0]->get_active) });
    $auto_buttons[1]->set_active(1) if $auto_mode->{user};
    $auto_buttons[0]->set_active(1) if !$auto_mode->{user};

    my $x_box;
    run_boot_window(N("System mode"),
                    [
                     1, gtknew('VBox', spacing => 5, children_tight => [
                                  gtksignal_connect(gtkset_active(gtknew('CheckButton', text => N("Launch the graphical environment when your system starts")),
                                                                  $x_mode),
                                                    clicked => sub {
                                                        $x_box->set_sensitive(!$x_mode);
                                                        $x_mode = !$x_mode;
                                                    }),
                                  $x_box = gtknew('VBox', sensitive => $x_mode, children_tight => [
                                            gtknew('VBox', children_tight => [ @auto_buttons ]),
                                            $auto_box
                                           ]) ])
                    ],
                    sub {
                        Xconfig::various::runlevel($x_mode ? 5 : 3);
                        $::testing and return;
                        if ($auto_buttons[1]->get_active) {
                            $auto_mode->{user} = $user_combo->entry->get_text;
                            $auto_mode->{desktop} = $desktop_combo->entry->get_text;
			} else {
                            $auto_mode->{user} = undef;
                            $auto_mode->{desktop} = undef;
                        }
                        any::set_autologin($in->do_pkgs, $auto_mode);
                    });
}


#-------------------------------------------------------------
# launch autologin functions
#-------------------------------------------------------------

sub change_image {
    my ($boot_pic, $theme, $res) = @_;
    my $img_file = bootsplash::theme_get_image_for_resolution($theme, $res);
    -f $img_file or return;
    my $boot_pixbuf = gtknew('Pixbuf', file => $img_file);
    $boot_pixbuf = $boot_pixbuf->scale_simple(300, 200, 'nearest');
    $boot_pic->set_from_pixbuf($boot_pixbuf);
}

sub set_splash_append {
    my ($val) = @_;
    bootloader::set_append_with_key($bootloader, 'splash', undef);
    bootloader::set_append_with_key($bootloader, 'splash', $val);
    modify_bootloader($bootloader, $all_hds);
}

sub enable_framebuffer() {
    my $vga = bootsplash::get_framebuffer_resolution();
    my ($current_entry) = $cmdline =~ /^BOOT_IMAGE=(\S+)/;
    my %entries = (
                   $current_entry => 1
                  );
    local $::isWizard = 1;
    local $::Wizard_no_previous = 1;
    local $::Wizard_finished = 1;
    $::Wizard_title = N("Boot Style Configuration");
    eval {
        $in->ask_from(N("Video mode"),
                      N("Please choose a video mode, it will be applied to each of the boot entries selected below.
Be sure your video card supports the mode you choose."),
                      [
                       { label => N("Video mode"), val => \$vga,
                         list => [ '', Xconfig::resolution_and_depth::bios_vga_modes() ],
                         format => \&Xconfig::resolution_and_depth::to_string
                       },
                       map {
                           { text => $_->{label}, val => \$entries{$_->{label}}, type => 'bool' };
                       } grep { $_->{label} !~ /failsafe|floppy|memtest/ } @{$bootloader->{entries}}
                      ]);
        if ($vga) {
            $vga = $vga->{bios} if ref($vga);
            while (my ($label, $e) = each %entries) {
                $e or next;
                my $entry = find { $_->{label} eq $label } @{$bootloader->{entries}};
                $entry->{vga} = $vga;
            }
            modify_bootloader($bootloader, $all_hds);
        }
    };
    die if $@ && $@ !~ /^wizcancel/;
    $::WizardWindow->destroy unless $::isEmbedded;
    $vga;
}

sub modify_bootloader {
    my ($bootloader, $all_hds) = @_;
    bootloader::action($bootloader, 'write', $all_hds);
    bootloader::action($bootloader, 'when_config_changed');
}