Commit 384681ff authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

riped out get_which_output from applet-lib and put it in these new files

Sat Mar 28 15:23:33 1998  George Lebl  <jirka@5z.com>

        * panel-util.[ch]: riped out get_which_output from
          applet-lib and put it in these new files while renaming
          it to get_full_path.

        * Makefile.am: link in the new files

        * panel-widget.c: temporairly disable dnd code as it
          doesn't work

        * main.c: call get_full_path from load applet

        * applet-lib.cc: add timeouts for contacting the panel
          so that applets don't get "lost" due to a race
parent c5298c88
Sat Mar 28 15:23:33 1998 George Lebl <jirka@5z.com>
* panel-util.[ch]: riped out get_which_output from
applet-lib and put it in these new files while renaming
it to get_full_path.
* Makefile.am: link in the new files
* panel-widget.c: temporairly disable dnd code as it
doesn't work
* main.c: call get_full_path from load applet
* applet-lib.cc: add timeouts for contacting the panel
so that applets don't get "lost" due to a race
Fri Mar 27 01:48:57 1998 George Lebl <jirka@5z.com> Fri Mar 27 01:48:57 1998 George Lebl <jirka@5z.com>
* panel-widget.c: dnd code in, but it doesn't work, needs * panel-widget.c: dnd code in, but it doesn't work, needs
......
Sat Mar 28 15:23:33 1998 George Lebl <jirka@5z.com>
* panel-util.[ch]: riped out get_which_output from
applet-lib and put it in these new files while renaming
it to get_full_path.
* Makefile.am: link in the new files
* panel-widget.c: temporairly disable dnd code as it
doesn't work
* main.c: call get_full_path from load applet
* applet-lib.cc: add timeouts for contacting the panel
so that applets don't get "lost" due to a race
Fri Mar 27 01:48:57 1998 George Lebl <jirka@5z.com> Fri Mar 27 01:48:57 1998 George Lebl <jirka@5z.com>
* panel-widget.c: dnd code in, but it doesn't work, needs * panel-widget.c: dnd code in, but it doesn't work, needs
......
...@@ -31,6 +31,7 @@ lib_LTLIBRARIES = libpanel_applet.la ...@@ -31,6 +31,7 @@ lib_LTLIBRARIES = libpanel_applet.la
libpanel_applet_la_SOURCES = \ libpanel_applet_la_SOURCES = \
applet-lib.cc \ applet-lib.cc \
mico-parse.cc \ mico-parse.cc \
panel-util.c \
$(CORBA_SOURCES) $(CORBA_SOURCES)
#libpanel_appletinclude_HEADERS = applet-lib.h \ #libpanel_appletinclude_HEADERS = applet-lib.h \
...@@ -67,6 +68,7 @@ panel_SOURCES = \ ...@@ -67,6 +68,7 @@ panel_SOURCES = \
panel_config_global.h \ panel_config_global.h \
panel-widget.c \ panel-widget.c \
panel-widget.h \ panel-widget.h \
panel-util.c \
$(CORBA_SOURCES) $(CORBA_SOURCES)
panel_LDADD = $(GNOME_LIBDIR) $(MICO_LIBS) -lXt $(GNOMEUI_LIBS) $(INTLLIBS) panel_LDADD = $(GNOME_LIBDIR) $(MICO_LIBS) -lXt $(GNOMEUI_LIBS) $(INTLLIBS)
......
...@@ -86,18 +86,25 @@ gnome_panel_applet_init_corba (void) ...@@ -86,18 +86,25 @@ gnome_panel_applet_init_corba (void)
char *name; char *name;
char *iior; char *iior;
char hostname [1024]; char hostname [1024];
int i;
gethostname (hostname, sizeof (hostname)); gethostname (hostname, sizeof (hostname));
if (hostname [0] == 0) if (hostname [0] == 0)
strcpy (hostname, "unknown-host"); strcpy (hostname, "unknown-host");
name = g_copy_strings ("/CORBA-servers/Panel-", hostname, /*do a 20 second timeout until we get the iior*/
"/DISPLAY-", getenv ("DISPLAY"), NULL); for(i=0;i<20;i++) {
name = g_copy_strings ("/CORBA-servers/Panel-", hostname,
"/DISPLAY-", getenv ("DISPLAY"), NULL);
iior = gnome_config_get_string (name); iior = gnome_config_get_string (name);
g_free (name); g_free (name);
if (!iior) if(iior)
break;
sleep(1);
}
if(!iior)
return 0; return 0;
panel_initialize_corba (&orb_ptr, &boa_ptr); panel_initialize_corba (&orb_ptr, &boa_ptr);
...@@ -117,18 +124,25 @@ gnome_panel_applet_reinit_corba (void) ...@@ -117,18 +124,25 @@ gnome_panel_applet_reinit_corba (void)
char *name; char *name;
char *iior; char *iior;
char hostname [1024]; char hostname [1024];
int i;
gethostname (hostname, sizeof (hostname)); gethostname (hostname, sizeof (hostname));
if (hostname [0] == 0) if (hostname [0] == 0)
strcpy (hostname, "unknown-host"); strcpy (hostname, "unknown-host");
name = g_copy_strings ("/CORBA-servers/Panel-", hostname, /*do a 20 second timeout until we get the iior*/
"/DISPLAY-", getenv ("DISPLAY"), NULL); for(i=0;i<20;i++) {
name = g_copy_strings ("/CORBA-servers/Panel-", hostname,
"/DISPLAY-", getenv ("DISPLAY"), NULL);
iior = gnome_config_get_string (name); iior = gnome_config_get_string (name);
g_free (name); g_free (name);
if (!iior) if(iior)
break;
sleep(1);
}
if(!iior)
return 0; return 0;
CORBA::Object_var obj = orb_ptr->string_to_object (iior); CORBA::Object_var obj = orb_ptr->string_to_object (iior);
...@@ -277,9 +291,27 @@ gnome_panel_applet_request_id (char *path, ...@@ -277,9 +291,27 @@ gnome_panel_applet_request_id (char *path,
char *cfg = NULL; char *cfg = NULL;
char *globcfg = NULL; char *globcfg = NULL;
guint32 wid; guint32 wid;
int i;
/*reserve a spot and get an id for this applet*/ /*this is the first call to panel so we'll do a loop and timeout
*id = panel_client->applet_request_id(path,cfg,globcfg,wid); after 20 seconds if we don't find a panel*/
*id = -1;
for(i=0;i<20;i++) {
try {
/*reserve a spot and get an id for this applet*/
*id = panel_client->applet_request_id(path,cfg,
globcfg,wid);
} catch (...) {
sleep(1);
gnome_panel_applet_reinit_corba ();
continue;
}
break;
}
/*if the request_id never completed*/
if(*id == -1)
return g_strdup("Can't talk to a panel\n");
if(winid) if(winid)
*winid = wid; *winid = wid;
...@@ -399,69 +431,3 @@ move_grab_remove (GtkWidget *applet) ...@@ -399,69 +431,3 @@ move_grab_remove (GtkWidget *applet)
gdk_pointer_ungrab(GDK_CURRENT_TIME); gdk_pointer_ungrab(GDK_CURRENT_TIME);
gtk_grab_remove(applet); gtk_grab_remove(applet);
} }
/* this function might be a slight overkill, but it should work
perfect, hopefully it should be 100% buffer overrun safe too*/
char *
get_which_output(char *argv0)
{
char buf[PATH_MAX+2];
int cmdsize=100;
char *cmdbuf;
int i;
int fd[2];
if(!argv0)
return NULL;
if(*argv0 == '/')
return g_strdup(argv0);
if(strchr(argv0,'/')) {
char *curpath = getcwd(NULL,0);
char *outbuf;
if(!curpath)
return NULL;
outbuf = g_copy_strings(curpath,"/",argv0,NULL);
free(curpath);
realpath(outbuf,buf);
return g_strdup(buf);
}
if(pipe(fd) == -1)
return NULL;
/*dynamically reallocates cmdbuf until the command fits*/
for(;;) {
cmdbuf = (char *)g_malloc(cmdsize);
if(g_snprintf(cmdbuf, cmdsize, "sh -c 'which %s > /dev/fd/%d'",
argv0,fd[1])>-1)
break;
g_free(cmdbuf);
cmdsize*=2;
}
system(cmdbuf);
g_free(cmdbuf);
i=read(fd[0],buf,PATH_MAX+1);
close(fd[0]);
close(fd[1]);
if(i <= 0)
return NULL;
buf[i]='\0';
if(buf[i-1]=='\n')
buf[i-1]='\0';
if(buf[0]=='\0')
return NULL;
return g_strdup(buf);
}
#ifndef APPLET_LIB_H #ifndef APPLET_LIB_H
#define APPLET_LIB_H #define APPLET_LIB_H
#include "panel-util.h"
BEGIN_GNOME_DECLS BEGIN_GNOME_DECLS
typedef void (*AppletCallbackFunc)(int id, gpointer data); typedef void (*AppletCallbackFunc)(int id, gpointer data);
...@@ -24,8 +26,6 @@ void applet_corba_gtk_main (char *str); ...@@ -24,8 +26,6 @@ void applet_corba_gtk_main (char *str);
void move_grab_add (GtkWidget *applet); void move_grab_add (GtkWidget *applet);
void move_grab_remove (GtkWidget *applet); void move_grab_remove (GtkWidget *applet);
char * get_which_output(char *argv0);
END_GNOME_DECLS END_GNOME_DECLS
#endif #endif
...@@ -551,7 +551,7 @@ main(int argc, char **argv) ...@@ -551,7 +551,7 @@ main(int argc, char **argv)
this is the string that we identify as when we ask for the this is the string that we identify as when we ask for the
spot*/ spot*/
/* /*
mypath = get_which_output(argv[0]); mypath = get_full_path(argv[0]);
if(!mypath) if(!mypath)
return 1;*/ return 1;*/
/* we pass an id starting with # to the panel to identify us, /* we pass an id starting with # to the panel to identify us,
......
...@@ -76,7 +76,7 @@ main(int argc, char *argv[]) ...@@ -76,7 +76,7 @@ main(int argc, char *argv[])
guint32 winid; guint32 winid;
char *myinvoc; char *myinvoc;
myinvoc = get_which_output(argv[0]); myinvoc = get_full_path(argv[0]);
if(!myinvoc) if(!myinvoc)
return 1; return 1;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "drawer.h" #include "drawer.h"
#include "mico-glue.h" #include "mico-glue.h"
#include "mico-parse.h" #include "mico-parse.h"
#include "panel-util.h"
GList *panels = NULL; GList *panels = NULL;
GList *applets = NULL; GList *applets = NULL;
...@@ -42,26 +43,33 @@ load_applet(char *id, char *params, int pos, int panel, char *cfgpath) ...@@ -42,26 +43,33 @@ load_applet(char *id, char *params, int pos, int panel, char *cfgpath)
{ {
if(strcmp(id,EXTERN_ID) == 0) { if(strcmp(id,EXTERN_ID) == 0) {
gchar *command; gchar *command;
gchar *fullparams;
/*make it an absolute path, same as the applets will
interpret it and the applets will sign themselves as
this, so it has to be exactly the same*/
fullparams = get_full_path(params);
/*start nothing, applet is taking care of everything*/ /*start nothing, applet is taking care of everything*/
if(params == NULL || if(params == NULL ||
params[0] == '\0') params[0] == '\0')
return; return;
reserve_applet_spot (id, params, panel, pos, cfgpath, reserve_applet_spot (id, fullparams, panel, pos, cfgpath,
APPLET_EXTERN_PENDING); APPLET_EXTERN_PENDING);
/*'#' marks an applet that will take care of starting /*'#' marks an applet that will take care of starting
itself but wants us to reserve a spot for it*/ itself but wants us to reserve a spot for it*/
if(params[0]!='#') { if(params[0]!='#') {
/*this applet is dumb and wants us to start it :)*/ /*this applet is dumb and wants us to start it :)*/
command = g_copy_strings ("(true;", params, ") &", command = g_copy_strings ("(true;", fullparams, ") &",
NULL); NULL);
system (command); system (command);
g_free (command); g_free (command);
} }
g_free(fullparams);
} else if(strcmp(id,MENU_ID) == 0) { } else if(strcmp(id,MENU_ID) == 0) {
Menu *menu; Menu *menu;
......
#include <glib.h>
#include <fcntl.h>
#include "panel-util.h"
/* this function might be a slight overkill, but it should work
perfect, hopefully it should be 100% buffer overrun safe too*/
char *
get_full_path(char *argv0)
{
char buf[PATH_MAX+2];
int cmdsize=100;
char *cmdbuf;
int i;
int fd[2];
if(!argv0)
return NULL;
if(*argv0 == '/')
return g_strdup(argv0);
if(strchr(argv0,'/')) {
char *curpath = getcwd(NULL,0);
char *outbuf;
if(!curpath)
return NULL;
outbuf = g_copy_strings(curpath,"/",argv0,NULL);
free(curpath);
realpath(outbuf,buf);
return g_strdup(buf);
}
if(pipe(fd) == -1)
return NULL;
/*dynamically reallocates cmdbuf until the command fits*/
for(;;) {
cmdbuf = (char *)g_malloc(cmdsize);
if(g_snprintf(cmdbuf, cmdsize, "sh -c 'which %s > /dev/fd/%d'",
argv0,fd[1])>-1)
break;
g_free(cmdbuf);
cmdsize*=2;
}
system(cmdbuf);
g_free(cmdbuf);
i=read(fd[0],buf,PATH_MAX+1);
close(fd[0]);
close(fd[1]);
if(i <= 0)
return NULL;
buf[i]='\0';
if(buf[i-1]=='\n')
buf[i-1]='\0';
if(buf[0]=='\0')
return NULL;
return g_strdup(buf);
}
#ifndef _PANEL_UTIL_H_
#define _PANEL_UTIL_H_
#include <gnome.h>
BEGIN_GNOME_DECLS
char *get_full_path(char *argv0);
END_GNOME_DECLS
#endif
...@@ -1091,6 +1091,7 @@ panel_widget_dnd_drop(GtkWidget *widget, GdkEvent *event, gpointer data) ...@@ -1091,6 +1091,7 @@ panel_widget_dnd_drop(GtkWidget *widget, GdkEvent *event, gpointer data)
return FALSE; return FALSE;
panel_widget_add(PANEL_WIDGET(panel),applet,pos); panel_widget_add(PANEL_WIDGET(panel),applet,pos);
puts("\n\nDROP\n\n");
return TRUE; return TRUE;
} }
...@@ -1276,12 +1277,12 @@ panel_widget_new (gint size, ...@@ -1276,12 +1277,12 @@ panel_widget_new (gint size,
panel_widget_pop_down(panel); panel_widget_pop_down(panel);
/*set up drag'n'drop (the drop)*/ /*set up drag'n'drop (the drop)*/
gtk_signal_connect (GTK_OBJECT (panel), /*gtk_signal_connect (GTK_OBJECT (panel),
"drop_data_available_event", "drop_data_available_event",
GTK_SIGNAL_FUNC(panel_widget_dnd_drop), GTK_SIGNAL_FUNC(panel_widget_dnd_drop),
NULL); NULL);
gtk_widget_dnd_drop_set (GTK_WIDGET(panel), TRUE, gtk_widget_dnd_drop_set (GTK_WIDGET(panel), TRUE,
applet_drop_types, 1, FALSE); applet_drop_types, 1, FALSE);*/
return GTK_WIDGET(panel); return GTK_WIDGET(panel);
...@@ -1350,6 +1351,9 @@ panel_widget_applet_move_to_cursor(PanelWidget *panel) ...@@ -1350,6 +1351,9 @@ panel_widget_applet_move_to_cursor(PanelWidget *panel)
/*gtk_signal_emit(GTK_OBJECT(panel), /*gtk_signal_emit(GTK_OBJECT(panel),
panel_widget_signals[APPLET_MOVE_SIGNAL], panel_widget_signals[APPLET_MOVE_SIGNAL],
panel->currently_dragged_applet);*/ panel->currently_dragged_applet);*/
/*gtk_signal_emit_by_name(
GTK_OBJECT(panel->currently_dragged_applet),
"drag_request_event");*/
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
...@@ -1515,8 +1519,6 @@ panel_widget_dnd_drag_request(GtkWidget *widget, GdkEvent *event, gpointer data) ...@@ -1515,8 +1519,6 @@ panel_widget_dnd_drag_request(GtkWidget *widget, GdkEvent *event, gpointer data)
gtk_widget_dnd_data_set (widget, event, &widget, sizeof(widget)); gtk_widget_dnd_data_set (widget, event, &widget, sizeof(widget));
puts("test");
return TRUE; return TRUE;
} }
...@@ -1531,6 +1533,8 @@ panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos) ...@@ -1531,6 +1533,8 @@ panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos)
g_return_val_if_fail(applet,-1); g_return_val_if_fail(applet,-1);
g_return_val_if_fail(pos>=0,-1); g_return_val_if_fail(pos>=0,-1);
printf("ADDING at pos: %d\n",pos);
if(panel->snapped == PANEL_DRAWER) { if(panel->snapped == PANEL_DRAWER) {
if(pos >= panel->size && if(pos >= panel->size &&
panel->drawer_drop_zone_pos == DROP_ZONE_LEFT) { panel->drawer_drop_zone_pos == DROP_ZONE_LEFT) {
...@@ -1579,12 +1583,12 @@ panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos) ...@@ -1579,12 +1583,12 @@ panel_widget_add (PanelWidget *panel, GtkWidget *applet, gint pos)
bind_top_applet_events(panel,applet); bind_top_applet_events(panel,applet);
/*set up drag'n'drop (the drag)*/ /*set up drag'n'drop (the drag)*/
gtk_signal_connect (GTK_OBJECT (panel), /*gtk_signal_connect (GTK_OBJECT (panel),
"drag_request_event", "drag_request_event",
GTK_SIGNAL_FUNC(panel_widget_dnd_drag_request), GTK_SIGNAL_FUNC(panel_widget_dnd_drag_request),
NULL); NULL);
gtk_widget_dnd_drag_set (GTK_WIDGET(panel), TRUE, gtk_widget_dnd_drag_set (GTK_WIDGET(panel), TRUE,
applet_drag_types, 1); applet_drag_types, 1);*/
return i; return i;
} }
...@@ -1855,6 +1859,8 @@ panel_widget_restore_state(PanelWidget *panel) ...@@ -1855,6 +1859,8 @@ panel_widget_restore_state(PanelWidget *panel)
} }
#if 0 #if 0
/*this does not really work, it's old test code, in the unlikely event
of a water landing, you can use this piece of code as a floatation device*/
int int
main(int argc, char **argv) main(int argc, char **argv)
......
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