Commit 6d67edf3 authored by George Lebl's avatar George Lebl

added window reparenting, only rudimentary stuff - George

parent 0c1ca6d9
......@@ -4,6 +4,7 @@ Makefile
_libs
.libs
panel
clock_applet
module_test
panelrc
.exrc
......@@ -4,7 +4,7 @@ SUBDIRS = menu mailcheck clock launcher batmon netwatch logout \
INCLUDES = \
-I$(includedir) $(X_CFLAGS)
bin_PROGRAMS = panel
bin_PROGRAMS = panel clock_applet
panel_SOURCES = \
gdkextra.c \
......@@ -23,6 +23,11 @@ panel_SOURCES = \
panel_LDADD = $(GNOME_LIBDIR) $(GNOMEUI_LIBS) $(DL_LIB)
clock_applet_SOURCES = \
clock.c
clock_applet_LDADD = $(GNOME_LIBDIR) $(GNOMEUI_LIBS)
data_DATA = panelrc
## Why not just make this via configure? Because @datadir@ will be
......
/*
* GNOME time/date display module.
* (C) 1997 The Free Software Foundation
*
* Authors: Miguel de Icaza
* Federico Mena
*
* Feel free to implement new look and feels :-)
*/
#include <stdio.h>
#ifdef HAVE_LIBINTL
# include <libintl.h>
#endif
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <time.h>
#include <gnome.h>
#include <gdk/gdkx.h>
#define CLOCK_DATA "clock_data"
typedef void (*ClockUpdateFunc) (GtkWidget *clock, time_t current_time);
typedef struct {
int timeout;
ClockUpdateFunc update_func;
} ClockData;
typedef struct {
GtkWidget *date;
GtkWidget *time;
} ComputerClock;
static void
free_data(GtkWidget *widget, gpointer data)
{
g_free(data);
}
static int
clock_timeout_callback (gpointer data)
{
time_t current_time;
GtkWidget *clock;
ClockData *cd;
time (&current_time);
clock = data;
cd = gtk_object_get_data(GTK_OBJECT(clock), CLOCK_DATA);
(*cd->update_func) (clock, current_time);
return 1;
}
static void
computer_clock_update_func(GtkWidget *clock, time_t current_time)
{
ComputerClock *cc;
char *strtime;
char date[20], hour[20];
cc = gtk_object_get_user_data(GTK_OBJECT(clock));
strtime = ctime (&current_time);
strncpy (date, strtime, 10);
date[10] = '\0';
gtk_label_set (GTK_LABEL (cc->date), date);
strtime += 11;
strncpy (hour, strtime, 5);
hour[5] = '\0';
gtk_label_set (GTK_LABEL (cc->time), hour);
}
static void
create_computer_clock_widget(GtkWidget **clock, ClockUpdateFunc *update_func)
{
GtkWidget *frame;
GtkWidget *align;
GtkWidget *vbox;
ComputerClock *cc;
frame = gtk_frame_new(NULL);
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
gtk_widget_show(frame);
align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
gtk_container_border_width(GTK_CONTAINER(align), 4);
gtk_container_add(GTK_CONTAINER(frame), align);
gtk_widget_show(align);
vbox = gtk_vbox_new(FALSE, FALSE);
gtk_container_add(GTK_CONTAINER(align), vbox);
gtk_widget_show(vbox);
cc = g_new(ComputerClock, 1);
cc->date = gtk_label_new("");
cc->time = gtk_label_new("");
gtk_box_pack_start_defaults(GTK_BOX(vbox), cc->date);
gtk_box_pack_start_defaults(GTK_BOX(vbox), cc->time);
gtk_widget_show(cc->date);
gtk_widget_show(cc->time);
gtk_object_set_user_data(GTK_OBJECT(frame), cc);
gtk_signal_connect(GTK_OBJECT(frame), "destroy",
(GtkSignalFunc) free_data,
cc);
*clock = frame;
*update_func = computer_clock_update_func;
}
static void
destroy_clock (GtkWidget *widget, void *data)
{
ClockData *cd;
cd = gtk_object_get_data(GTK_OBJECT(widget), CLOCK_DATA);
gtk_timeout_remove (cd->timeout);
g_free(cd);
}
static GtkWidget *
create_clock_widget (GtkWidget *window)
{
ClockData *cd;
GtkWidget *clock;
time_t current_time;
cd = g_new(ClockData, 1);
/*FIXME: different clock types here*/
create_computer_clock_widget(&clock, &cd->update_func);
/* Install timeout handler */
cd->timeout = gtk_timeout_add(3000, clock_timeout_callback, clock);
gtk_object_set_data(GTK_OBJECT(clock), CLOCK_DATA, cd);
gtk_signal_connect(GTK_OBJECT(clock), "destroy",
(GtkSignalFunc) destroy_clock,
NULL);
/* Call the clock's update function so that it paints its first state */
time(&current_time);
(*cd->update_func) (clock, current_time);
return clock;
}
int
main(int argc, char **argv)
{
GtkWidget *clock;
GtkWidget *eb;
GtkWidget *window;
gnome_init(&argc, &argv);
eb = gtk_event_box_new();
gtk_widget_show(eb);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
clock = create_clock_widget (GTK_WIDGET(window));
gtk_widget_show(clock);
gtk_container_add(GTK_CONTAINER(eb),clock);
gtk_container_add(GTK_CONTAINER(window),eb);
gtk_widget_show(window);
printf ("The window id is: %d\n", GDK_WINDOW_XWINDOW (clock->window));
gtk_main();
return 0;
}
......@@ -19,6 +19,8 @@
#include "menu.h"
#include "panel_config.h"
#include <gdk/gdkx.h>
#define APPLET_CMD_FUNC "panel_applet_cmd_func"
#define APPLET_FLAGS "panel_applet_flags"
......@@ -619,6 +621,29 @@ add_main_menu(GtkWidget *widget, gpointer data)
create_applet("Menu",".:1",PANEL_UNKNOWN_APPLET_POSITION,1);
}
static void
add_reparent(GtkWidget *widget, gpointer data)
{
int id;
GtkWidget *eb;
GdkWindow *win;
int w,h;
puts("Enter window ID to reparent:");
scanf("%d",&id);
eb = gtk_event_box_new();
gtk_widget_show(eb);
win = gdk_window_foreign_new(id);
gdk_window_get_size(win,&w,&h);
gtk_widget_set_usize(eb,w,h);
panel_widget_add(PANEL_WIDGET(panels->data), eb, 0);
gdk_window_reparent(win,eb->window,0,0);
}
GtkWidget *
create_panel_root_menu(PanelWidget *panel)
{
......@@ -634,6 +659,13 @@ create_panel_root_menu(PanelWidget *panel)
gtk_menu_append(GTK_MENU(panel_menu), menuitem);
gtk_widget_show(menuitem);
menuitem = gtk_menu_item_new_with_label(_("Add reparent"));
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
(GtkSignalFunc) add_reparent,
panel);
gtk_menu_append(GTK_MENU(panel_menu), menuitem);
gtk_widget_show(menuitem);
menuitem = gtk_menu_item_new_with_label(_("Add main menu applet"));
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
(GtkSignalFunc) add_main_menu,
......@@ -755,6 +787,8 @@ register_toy(GtkWidget *applet, char *id, int pos, int panel, long flags)
if(strcmp(id,"Menu")==0)
menu_count++;
printf ("The window id for %s is: %d\n",id, GDK_WINDOW_XWINDOW (eventbox->window));
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment