New logout dialog

Some compilation fix with the new FLTK versions
This commit is contained in:
Sanel Zukan 2008-10-08 13:22:45 +00:00
parent 5687eae0ac
commit a28b95f255
5 changed files with 95 additions and 478 deletions

View File

@ -112,6 +112,7 @@ static int get_int_property_value(Atom at) {
return ret;
}
#if 0
static int get_string_property_value(Atom at, char* txt, int txt_len) {
XTextProperty names;
XGetTextProperty(fl_display, RootWindow(fl_display, fl_screen), &names, at);
@ -130,6 +131,7 @@ static int get_string_property_value(Atom at, char* txt, int txt_len) {
XFreeStringList(vnames);
return 1;
}
#endif
/*
* This is re-implementation of XmuClientWindow() so I don't have to link code with libXmu.
@ -589,7 +591,6 @@ void EvokeService::service_watcher(int pid, int ret) {
write(wake_up_pipe[1], &ret, sizeof(int));
}
#include <FL/fl_ask.H>
void EvokeService::wake_up(int fd) {
puts("=== wake_up() ===");
@ -630,7 +631,6 @@ void EvokeService::wake_up(int fd) {
break;
case 127:
edelib::alert(_("Program not found"));
//fl_alert(_("Program not found"));
break;
case 126:
edelib::alert(_("Program not executable"));
@ -750,6 +750,7 @@ int EvokeService::handle(const XEvent* xev) {
}
if(xev->type == PropertyNotify) {
#if 0
if(xev->xproperty.atom == _ede_spawn) {
char buff[1024];
if(get_string_property_value(_ede_spawn, buff, sizeof(buff))) {
@ -759,6 +760,7 @@ int EvokeService::handle(const XEvent* xev) {
EVOKE_LOG("Got _EDE_EVOKE_SPAWN with malformed data. Ignoring...\n");
}
}
#endif
if(xev->xproperty.atom == _ede_evoke_quit) {
int val = get_int_property_value(_ede_evoke_quit);
@ -778,7 +780,7 @@ int EvokeService::handle(const XEvent* xev) {
int dh = DisplayHeight(fl_display, fl_screen);
// TODO: add XDM service permissions
printf("got %i\n", logout_dialog(dw, dh, 1, 1));
printf("got %i\n", logout_dialog(dw, dh, LOGOUT_OPT_SHUTDOWN | LOGOUT_OPT_RESTART));
//quit_x11();
} else
EVOKE_LOG("Got _EDE_EVOKE_SHUTDOWN_ALL with bad code (%i). Ignoring...\n", val);

View File

@ -3,483 +3,93 @@
*
* Evoke, head honcho of everything
* Part of Equinox Desktop Environment (EDE).
* Copyright (c) 2000-2007 EDE Authors.
* Copyright (c) 2008 EDE Authors.
*
* This program is licensed under terms of the
* GNU General Public License version 2 or newer.
* See COPYING for details.
*/
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Round_Button.H>
#include <FL/Fl_RGB_Image.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl.H>
#include <FL/x.H>
#include <string.h> // memset
#include <edelib/Nls.h>
#include "Logout.h"
static int logout_ret;
static Fl_Double_Window* win;
static Fl_Round_Button* rb1;
static Fl_Round_Button* rb2;
static Fl_Round_Button* rb3;
// Note that order of initialized items is important so LOGOUT_OPT_XXX can work
struct LogoutOptions {
const char* opt_short;
const char* opt_long;
} logout_options[] = {
{ _("Logout"), _("This option will close all programs and logs out from the current session") },
{ _("Restart"), _("This option will restart the computer closing all running programs") },
{ _("Shut down"), _("This option will shut down the computer closing all running programs") }
};
unsigned char* take_x11_screenshot(unsigned char *p, int X, int Y, int w, int h, int alpha);
unsigned char* make_darker(unsigned char *p, int X, int Y, int w, int h);
static void rb_cb(Fl_Widget*, void* r) {
Fl_Round_Button* rb = (Fl_Round_Button*)r;
if(rb == rb2) {
rb1->value(0);
rb3->value(0);
} else if(rb == rb3) {
rb1->value(0);
rb2->value(0);
} else {
rb2->value(0);
rb3->value(0);
}
rb->value(1);
}
static Fl_Window* win;
static Fl_Box* description;
static int ret_option;
static void ok_cb(Fl_Widget*, void*) {
if(rb1->value())
logout_ret = LOGOUT_LOGOUT;
else if(rb2->value())
logout_ret = LOGOUT_RESTART;
else
logout_ret = LOGOUT_SHUTDOWN;
win->hide();
}
static void cancel_cb(Fl_Widget*, void*) {
logout_ret = LOGOUT_CANCEL;
ret_option = LOGOUT_RET_CANCEL;
win->hide();
}
int logout_dialog(int screen_w, int screen_h, bool disable_restart, bool disable_shutdown) {
logout_ret = 0;
unsigned char* imgdata = NULL;
imgdata = take_x11_screenshot(imgdata, 0, 0, screen_w, screen_h, 0);
if(imgdata)
imgdata = make_darker(imgdata, 0, 0, screen_w, screen_h);
static void option_cb(Fl_Widget*, void* o) {
Fl_Choice* c = (Fl_Choice*)o;
int v = c->value();
//win = new Fl_Double_Window(365, 265, 325, 185, _("Logout, restart or shutdown"));
win = new Fl_Double_Window(0, 0, screen_w, screen_h, _("Logout, restart or shutdown"));
description->label(logout_options[v].opt_long);
ret_option = v;
}
int logout_dialog(int screen_w, int screen_h, int opt) {
ret_option = LOGOUT_RET_LOGOUT;
win = new Fl_Window(335, 180, _("Quit EDE?"));
win->begin();
Fl_Box* bb = new Fl_Box(0, 0, win->w(), win->h());
Fl_RGB_Image* img = new Fl_RGB_Image(imgdata, win->w(), win->h());
img->alloc_array = 1;
bb->image(img);
Fl_Box* b1 = new Fl_Box(10, 9, 315, 25, _("How do you want to quit?"));
b1->labelfont(1);
b1->align(196|FL_ALIGN_INSIDE);
//Fl_Group* g = new Fl_Group(365, 265, 325, 185);
Fl_Group* g = new Fl_Group(0, 0, 325, 185);
g->box(FL_THIN_UP_BOX);
g->begin();
Fl_Box* b = new Fl_Box(10, 9, 305, 39, _("Logout, restart or shut down the computer ?"));
b->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_WRAP);
b->labelfont(FL_HELVETICA_BOLD);
Fl_Choice* c = new Fl_Choice(10, 45, 315, 25);
c->down_box(FL_BORDER_BOX);
rb1 = new Fl_Round_Button(25, 60, 275, 20, _("Logout from the current session"));
rb1->down_box(FL_ROUND_DOWN_BOX);
rb1->value(1);
rb1->callback(rb_cb, rb1);
// fill choice menu
c->add(logout_options[0].opt_short, 0, option_cb, c);
if(opt & LOGOUT_OPT_RESTART)
c->add(logout_options[1].opt_short, 0, option_cb, c);
if(opt & LOGOUT_OPT_SHUTDOWN)
c->add(logout_options[2].opt_short, 0, option_cb, c);
rb2 = new Fl_Round_Button(25, 85, 275, 20, _("Restart the computer"));
rb2->down_box(FL_ROUND_DOWN_BOX);
rb2->value(0);
rb2->callback(rb_cb, rb2);
if(disable_restart)
rb2->deactivate();
description = new Fl_Box(10, 80, 315, 55);
description->align(197|FL_ALIGN_INSIDE);
rb3 = new Fl_Round_Button(25, 110, 275, 20, _("Shut down the computer"));
rb3->down_box(FL_ROUND_DOWN_BOX);
rb3->value(0);
rb3->callback(rb_cb, rb3);
if(disable_shutdown)
rb3->deactivate();
Fl_Button* ok = new Fl_Button(130, 150, 90, 25, _("&OK"));
ok->callback(ok_cb);
Fl_Button* cancel = new Fl_Button(225, 150, 90, 25, _("&Cancel"));
cancel->callback(cancel_cb);
g->end();
g->position(screen_w/2 - g->w()/2, screen_h/2 - g->h()/2);
//win->position(screen_w/2 - win->w()/2, screen_h/2 - win->h()/2);
// set to first menu item
c->value(0);
description->label(logout_options[0].opt_long);
Fl_Button* ok = new Fl_Button(140, 145, 90, 25, _("&OK"));
ok->callback(ok_cb, c);
Fl_Button* cancel = new Fl_Button(235, 145, 90, 25, _("&Cancel"));
cancel->callback(cancel_cb);
win->end();
win->clear_border();
win->set_override();
// so when X in titlebar was clicked, we can get LOGOUT_RET_CANCEL
win->callback(cancel_cb);
win->position(screen_w / 2 - win->w() / 2, screen_h / 2 - win->h() / 2);
win->show();
while(win->shown())
Fl::wait();
return logout_ret;
}
unsigned char* make_darker(unsigned char *p, int X, int Y, int w, int h) {
if(!p)
return 0;
unsigned char* pdata = p;
int step = 100;
for(int j = 0; j < h; j++) {
for(int i = 0; i < w; i++) {
// red
if(*pdata > step)
*pdata -= step;
else
*pdata = 0;
pdata++;
// green
if(*pdata > step)
*pdata -= step;
else
*pdata = 0;
pdata++;
// blue
if(*pdata > step)
*pdata -= step;
else
*pdata = 0;
pdata++;
}
}
return p;
}
// stolen from fl_read_image.cxx
unsigned char* take_x11_screenshot(unsigned char *p, int X, int Y, int w, int h, int alpha) {
XImage *image;
int i, maxindex;
int x, y; // Current X & Y in image
int d; // Depth of image
unsigned char *line, // Array to hold image row
*line_ptr; // Pointer to current line image
unsigned char *pixel; // Current color value
XColor colors[4096]; // Colors from the colormap...
unsigned char cvals[4096][3]; // Color values from the colormap...
unsigned index_mask,
index_shift,
red_mask,
red_shift,
green_mask,
green_shift,
blue_mask,
blue_shift;
//
// Under X11 we have the option of the XGetImage() interface or SGI's
// ReadDisplay extension which does all of the really hard work for
// us...
//
image = 0;
if (!image) {
image = XGetImage(fl_display, RootWindow(fl_display, fl_screen), X, Y, w, h, AllPlanes, ZPixmap);
}
if (!image) return 0;
d = alpha ? 4 : 3;
// Allocate the image data array as needed...
if (!p) p = new unsigned char[w * h * d];
// Initialize the default colors/alpha in the whole image...
memset(p, alpha, w * h * d);
// Check that we have valid mask/shift values...
if (!image->red_mask && image->bits_per_pixel > 12) {
// Greater than 12 bits must be TrueColor...
image->red_mask = fl_visual->visual->red_mask;
image->green_mask = fl_visual->visual->green_mask;
image->blue_mask = fl_visual->visual->blue_mask;
}
// Check if we have colormap image...
if (!image->red_mask) {
// Get the colormap entries for this window...
maxindex = fl_visual->visual->map_entries;
for (i = 0; i < maxindex; i ++) colors[i].pixel = i;
XQueryColors(fl_display, fl_colormap, colors, maxindex);
for (i = 0; i < maxindex; i ++) {
cvals[i][0] = colors[i].red >> 8;
cvals[i][1] = colors[i].green >> 8;
cvals[i][2] = colors[i].blue >> 8;
}
// Read the pixels and output an RGB image...
for (y = 0; y < image->height; y ++) {
pixel = (unsigned char *)(image->data + y * image->bytes_per_line);
line = p + y * w * d;
switch (image->bits_per_pixel) {
case 1 :
for (x = image->width, line_ptr = line, index_mask = 128;
x > 0;
x --, line_ptr += d) {
if (*pixel & index_mask) {
line_ptr[0] = cvals[1][0];
line_ptr[1] = cvals[1][1];
line_ptr[2] = cvals[1][2];
} else {
line_ptr[0] = cvals[0][0];
line_ptr[1] = cvals[0][1];
line_ptr[2] = cvals[0][2];
}
if (index_mask > 1) {
index_mask >>= 1;
} else {
index_mask = 128;
pixel ++;
}
}
break;
case 2 :
for (x = image->width, line_ptr = line, index_shift = 6;
x > 0;
x --, line_ptr += d) {
i = (*pixel >> index_shift) & 3;
line_ptr[0] = cvals[i][0];
line_ptr[1] = cvals[i][1];
line_ptr[2] = cvals[i][2];
if (index_shift > 0) {
index_mask >>= 2;
index_shift -= 2;
} else {
index_mask = 192;
index_shift = 6;
pixel ++;
}
}
break;
case 4 :
for (x = image->width, line_ptr = line, index_shift = 4;
x > 0;
x --, line_ptr += d) {
if (index_shift == 4) i = (*pixel >> 4) & 15;
else i = *pixel & 15;
line_ptr[0] = cvals[i][0];
line_ptr[1] = cvals[i][1];
line_ptr[2] = cvals[i][2];
if (index_shift > 0) {
index_shift = 0;
} else {
index_shift = 4;
pixel ++;
}
}
break;
case 8 :
for (x = image->width, line_ptr = line;
x > 0;
x --, line_ptr += d, pixel ++) {
line_ptr[0] = cvals[*pixel][0];
line_ptr[1] = cvals[*pixel][1];
line_ptr[2] = cvals[*pixel][2];
}
break;
case 12 :
for (x = image->width, line_ptr = line, index_shift = 0;
x > 0;
x --, line_ptr += d) {
if (index_shift == 0) {
i = ((pixel[0] << 4) | (pixel[1] >> 4)) & 4095;
} else {
i = ((pixel[1] << 8) | pixel[2]) & 4095;
}
line_ptr[0] = cvals[i][0];
line_ptr[1] = cvals[i][1];
line_ptr[2] = cvals[i][2];
if (index_shift == 0) {
index_shift = 4;
} else {
index_shift = 0;
pixel += 3;
}
}
break;
}
}
} else {
// RGB(A) image, so figure out the shifts & masks...
red_mask = image->red_mask;
red_shift = 0;
while ((red_mask & 1) == 0) {
red_mask >>= 1;
red_shift ++;
}
green_mask = image->green_mask;
green_shift = 0;
while ((green_mask & 1) == 0) {
green_mask >>= 1;
green_shift ++;
}
blue_mask = image->blue_mask;
blue_shift = 0;
while ((blue_mask & 1) == 0) {
blue_mask >>= 1;
blue_shift ++;
}
// Read the pixels and output an RGB image...
for (y = 0; y < image->height; y ++) {
pixel = (unsigned char *)(image->data + y * image->bytes_per_line);
line = p + y * w * d;
switch (image->bits_per_pixel) {
case 8 :
for (x = image->width, line_ptr = line;
x > 0;
x --, line_ptr += d, pixel ++) {
i = *pixel;
line_ptr[0] = 255 * ((i >> red_shift) & red_mask) / red_mask;
line_ptr[1] = 255 * ((i >> green_shift) & green_mask) / green_mask;
line_ptr[2] = 255 * ((i >> blue_shift) & blue_mask) / blue_mask;
}
break;
case 12 :
for (x = image->width, line_ptr = line, index_shift = 0;
x > 0;
x --, line_ptr += d) {
if (index_shift == 0) {
i = ((pixel[0] << 4) | (pixel[1] >> 4)) & 4095;
} else {
i = ((pixel[1] << 8) | pixel[2]) & 4095;
}
line_ptr[0] = 255 * ((i >> red_shift) & red_mask) / red_mask;
line_ptr[1] = 255 * ((i >> green_shift) & green_mask) / green_mask;
line_ptr[2] = 255 * ((i >> blue_shift) & blue_mask) / blue_mask;
if (index_shift == 0) {
index_shift = 4;
} else {
index_shift = 0;
pixel += 3;
}
}
break;
case 16 :
if (image->byte_order == LSBFirst) {
// Little-endian...
for (x = image->width, line_ptr = line;
x > 0;
x --, line_ptr += d, pixel += 2) {
i = (pixel[1] << 8) | pixel[0];
line_ptr[0] = 255 * ((i >> red_shift) & red_mask) / red_mask;
line_ptr[1] = 255 * ((i >> green_shift) & green_mask) / green_mask;
line_ptr[2] = 255 * ((i >> blue_shift) & blue_mask) / blue_mask;
}
} else {
// Big-endian...
for (x = image->width, line_ptr = line;
x > 0;
x --, line_ptr += d, pixel += 2) {
i = (pixel[0] << 8) | pixel[1];
line_ptr[0] = 255 * ((i >> red_shift) & red_mask) / red_mask;
line_ptr[1] = 255 * ((i >> green_shift) & green_mask) / green_mask;
line_ptr[2] = 255 * ((i >> blue_shift) & blue_mask) / blue_mask;
}
}
break;
case 24 :
if (image->byte_order == LSBFirst) {
// Little-endian...
for (x = image->width, line_ptr = line;
x > 0;
x --, line_ptr += d, pixel += 3) {
i = (((pixel[2] << 8) | pixel[1]) << 8) | pixel[0];
line_ptr[0] = 255 * ((i >> red_shift) & red_mask) / red_mask;
line_ptr[1] = 255 * ((i >> green_shift) & green_mask) / green_mask;
line_ptr[2] = 255 * ((i >> blue_shift) & blue_mask) / blue_mask;
}
} else {
// Big-endian...
for (x = image->width, line_ptr = line;
x > 0;
x --, line_ptr += d, pixel += 3) {
i = (((pixel[0] << 8) | pixel[1]) << 8) | pixel[2];
line_ptr[0] = 255 * ((i >> red_shift) & red_mask) / red_mask;
line_ptr[1] = 255 * ((i >> green_shift) & green_mask) / green_mask;
line_ptr[2] = 255 * ((i >> blue_shift) & blue_mask) / blue_mask;
}
}
break;
case 32 :
if (image->byte_order == LSBFirst) {
// Little-endian...
for (x = image->width, line_ptr = line;
x > 0;
x --, line_ptr += d, pixel += 4) {
i = (((((pixel[3] << 8) | pixel[2]) << 8) | pixel[1]) << 8) | pixel[0];
line_ptr[0] = 255 * ((i >> red_shift) & red_mask) / red_mask;
line_ptr[1] = 255 * ((i >> green_shift) & green_mask) / green_mask;
line_ptr[2] = 255 * ((i >> blue_shift) & blue_mask) / blue_mask;
}
} else {
// Big-endian...
for (x = image->width, line_ptr = line;
x > 0;
x --, line_ptr += d, pixel += 4) {
i = (((((pixel[0] << 8) | pixel[1]) << 8) | pixel[2]) << 8) | pixel[3];
line_ptr[0] = 255 * ((i >> red_shift) & red_mask) / red_mask;
line_ptr[1] = 255 * ((i >> green_shift) & green_mask) / green_mask;
line_ptr[2] = 255 * ((i >> blue_shift) & blue_mask) / blue_mask;
}
}
break;
}
}
}
// Destroy the X image we've read and return the RGB(A) image...
XDestroyImage(image);
return p;
return ret_option;
}

View File

@ -3,7 +3,7 @@
*
* Evoke, head honcho of everything
* Part of Equinox Desktop Environment (EDE).
* Copyright (c) 2000-2007 EDE Authors.
* Copyright (c) 2008 EDE Authors.
*
* This program is licensed under terms of the
* GNU General Public License version 2 or newer.
@ -13,11 +13,14 @@
#ifndef __LOGOUT_H__
#define __LOGOUT_H__
#define LOGOUT_CANCEL 0
#define LOGOUT_LOGOUT 1
#define LOGOUT_RESTART 2
#define LOGOUT_SHUTDOWN 3
#define LOGOUT_RET_CANCEL -1
#define LOGOUT_RET_LOGOUT 0
#define LOGOUT_RET_RESTART 1
#define LOGOUT_RET_SHUTDOWN 2
int logout_dialog(int screen_w, int screen_h, bool disable_restart = 0, bool disable_shutdown = 0);
#define LOGOUT_OPT_RESTART (1 << 1)
#define LOGOUT_OPT_SHUTDOWN (1 << 2)
int logout_dialog(int screen_w, int screen_h, int opt);
#endif

View File

@ -39,21 +39,28 @@ static void quit_signal(int sig) {
EvokeService::instance()->stop();
}
static void xmessage_handler(int, void*) {
static int xmessage_handler(int) {
#ifdef USE_FLTK_LOOP_EMULATION
XEvent xev;
while(XEventsQueued(fl_display, QueuedAfterReading)) {
XNextEvent(fl_display, &xev);
EvokeService::instance()->handle((const XEvent*)&xev);
}
return 1;
#else
return EvokeService::instance()->handle(fl_xevent);
#endif
}
#ifdef USE_FLTK_LOOP_EMULATION
static void xmessage_handler_fd(int, void*) {
xmessage_handler(0);
}
static int composite_handler(int ev) {
return EvokeService::instance()->composite_handle(fl_xevent);
}
#endif
static const char* next_param(int curr, char** argv, int argc) {
int j = curr + 1;
@ -64,7 +71,7 @@ static const char* next_param(int curr, char** argv, int argc) {
return argv[j];
}
void help(void) {
static void help(void) {
puts("Usage: evoke [OPTIONS]");
puts("EDE startup manager responsible for starting, quitting and tracking");
puts("various pieces of desktop environment and external programs.");
@ -236,7 +243,7 @@ int main(int argc, char** argv) {
* windows it already don't know.
*/
#ifdef USE_FLTK_LOOP_EMULATION
Fl::add_fd(ConnectionNumber(fl_display), 1, xmessage_handler);
Fl::add_fd(ConnectionNumber(fl_display), 1, xmessage_handler_fd);
Fl::add_handler(composite_handler);
#else
/*
@ -255,7 +262,7 @@ int main(int argc, char** argv) {
* send to xmessage_handler() and composite will wrongly draw the screen.
*/
if(XQLength(fl_display)) {
xmessage_handler(0, 0);
xmessage_handler(0);
continue;
}
#else

View File

@ -2,34 +2,29 @@
version 1.0108
header_name {.h}
code_name {.cxx}
Function {} {open selected
Function {} {open
} {
Fl_Window {} {open
xywh {365 265 325 185} type Double visible
xywh {479 284 335 180} type Double visible
} {
Fl_Box {} {
label {Logout, restart or shut down the computer ?}
xywh {10 9 305 39} labelfont 1 align 148
label {How do you want to quit?}
xywh {10 9 315 25} labelfont 1 align 212
}
Fl_Choice {} {open
xywh {10 45 315 25} down_box BORDER_BOX labelsize 14 textsize 14
} {}
Fl_Box {} {
label {This option will close all programs and logs out from the current session}
xywh {10 80 315 55} align 213
}
Fl_Button {} {
label {&OK} selected
xywh {140 145 90 25}
}
Fl_Button {} {
label {&Cancel}
xywh {225 150 90 25}
}
Fl_Button {} {
label {&OK}
xywh {130 150 90 25}
}
Fl_Round_Button {} {
label {Logout from the current session}
xywh {25 60 275 20} down_box ROUND_DOWN_BOX
}
Fl_Round_Button {} {
label {Restart the computer}
xywh {25 85 215 20} down_box ROUND_DOWN_BOX
}
Fl_Round_Button {} {
label {Shut down the computer}
xywh {25 110 215 20} down_box ROUND_DOWN_BOX
xywh {235 145 90 25}
}
}
}