[PATCH] GDM-2.4.4.3 Display optional info message before login



Dear George,

The below patch for gdm-2.4.4.3 adds a gdm.conf option
daemon/GdmInfoMsgFile= which if present and pointing to a file (e.g.
GdmInfoMsgFile=/etc/infotextfile) will be displayed in a modal dialog box
(which only has an "OK" button) before the user is prompted to log in.

I have implemented it both for the old gdmlogin and the new gdm greeter.

For the gdm greeter the format of the message is themable, e.g. in
Circles.xml one would add:

diff -urNp gdm-2.4.4.3.old/gui/greeter/themes/circles/circles.xml gdm-2.4.4.3/gui/greeter/themes/circles/circles.xml
--- gdm-2.4.4.3.old/gui/greeter/themes/circles/circles.xml	2003-09-30 15:28:59.000000000 +0100
+++ gdm-2.4.4.3/gui/greeter/themes/circles/circles.xml	2003-09-30 17:59:14.000000000 +0100
@@ -185,6 +185,11 @@
       </item>
     </fixed>
   </item>
+
+  <item type="label" id="info-msg-dialog-format">
+    <normal color="#000000" font="Sans 24"/>
+      <text></text>
+  </item>
 </greeter>

To get black text with a Sans 24 font.

We use this at Cambridge University to display some usage guidelines on
the public workstations before the user gets to log in.

I saw the mailing list post from Lukas Kubin asking if this is possible so
I thought I would submit the patch, perhaps others can benefit from this,
too.

Best regards,

	Anton
-- 
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Unix Support, Computing Service, University of Cambridge, CB2 3QH, UK
Linux NTFS maintainer / IRC: #ntfs on irc.freenode.net
WWW: http://linux-ntfs.sf.net/ & http://www-stu.christs.cam.ac.uk/~aia21/

diff -urNp gdm-2.4.4.3.old/config/gdm.conf gdm-2.4.4.3/config/gdm.conf
--- gdm-2.4.4.3.old/config/gdm.conf	2003-10-01 09:50:09.000000000 +0100
+++ gdm-2.4.4.3/config/gdm.conf	2003-09-30 18:05:55.000000000 +0100
@@ -95,6 +95,9 @@ XKeepsCrashing=/etc/gdm/XKeepsCrashing
 #RebootCommand=/usr/bin/reboot;/sbin/reboot;/sbin/shutdown -r now;/usr/sbin/shutdown -r now
 #HaltCommand=/usr/bin/poweroff;/sbin/poweroff;/sbin/shutdown -h now;/usr/sbin/shutdown -h now
 #SuspendCommand=
+# If InfoMsgFile points to a file, the greeter will display the contents of the
+# file in a modal dialog box before the user is allowed to log in.
+#InfoMsgFile=
 # Probably should not touch the below this is the standard setup
 ServAuthDir=/usr/var/gdm
 # This is our standard startup script.  A bit different from a normal
diff -urNp gdm-2.4.4.3.old/config/gdm.conf.in gdm-2.4.4.3/config/gdm.conf.in
--- gdm-2.4.4.3.old/config/gdm.conf.in	2003-09-22 22:50:52.000000000 +0100
+++ gdm-2.4.4.3/config/gdm.conf.in	2003-09-30 17:44:46.000000000 +0100
@@ -95,6 +95,9 @@ XKeepsCrashing= EXPANDED_SYSCONFDIR@/gdm
 #RebootCommand=/usr/bin/reboot;/sbin/reboot;/sbin/shutdown -r now;/usr/sbin/shutdown -r now
 #HaltCommand=/usr/bin/poweroff;/sbin/poweroff;/sbin/shutdown -h now;/usr/sbin/shutdown -h now
 #SuspendCommand=
+# If InfoMsgFile points to a file, the greeter will display the contents of the
+# file in a modal dialog box before the user is allowed to log in.
+#InfoMsgFile=
 # Probably should not touch the below this is the standard setup
 ServAuthDir= EXPANDED_AUTHDIR@
 # This is our standard startup script.  A bit different from a normal
diff -urNp gdm-2.4.4.3.old/daemon/gdm.h gdm-2.4.4.3/daemon/gdm.h
--- gdm-2.4.4.3.old/daemon/gdm.h	2003-09-25 17:40:32.000000000 +0100
+++ gdm-2.4.4.3/daemon/gdm.h	2003-09-30 17:49:42.000000000 +0100
@@ -149,6 +149,7 @@ enum {
 #define GDM_KEY_BASEXSESSION "daemon/BaseXsession=" EXPANDED_SYSCONFDIR "/gdm/Xsession"
 #define GDM_KEY_DEFAULTSESSION "daemon/DefaultSession=gnome.desktop"
 #define GDM_KEY_SUSPEND "daemon/SuspendCommand="
+#define GDM_KEY_INFO_MSG_FILE "daemon/InfoMsgFile="

 #define GDM_KEY_UAUTHDIR "daemon/UserAuthDir="
 #define GDM_KEY_UAUTHFB "daemon/UserAuthFBDir=/tmp"
diff -urNp gdm-2.4.4.3.old/gui/gdmlogin.c gdm-2.4.4.3/gui/gdmlogin.c
--- gdm-2.4.4.3.old/gui/gdmlogin.c	2003-09-22 23:11:46.000000000 +0100
+++ gdm-2.4.4.3/gui/gdmlogin.c	2003-10-01 09:42:00.000000000 +0100
@@ -90,6 +90,7 @@ static gchar *GdmSuspend;
 static gboolean GdmConfigAvailable;
 static gboolean GdmConfigAvailableReal;
 static gchar *GdmConfigurator;
+static gchar *GdmInfoMsgFile;
 static gint GdmXineramaScreen;
 static gchar *GdmLogo;
 static gchar *GdmWelcome;
@@ -720,6 +721,7 @@ gdm_login_parse_config (void)
     GdmSuspend = ve_config_get_string (config, GDM_KEY_SUSPEND);
     GdmConfigAvailableReal = GdmConfigAvailable = ve_config_get_bool (config, GDM_KEY_CONFIG_AVAILABLE);
     GdmConfigurator = ve_config_get_string (config, GDM_KEY_CONFIGURATOR);
+    GdmInfoMsgFile = ve_config_get_string (config, GDM_KEY_INFO_MSG_FILE);
     GdmTitleBar = ve_config_get_bool (config, GDM_KEY_TITLE_BAR);
     GdmLocaleFile = ve_config_get_string (config, GDM_KEY_LOCFILE);
     GdmSessionDir = ve_config_get_string (config, GDM_KEY_SESSDIR);
@@ -3559,6 +3561,7 @@ gdm_reread_config (int sig, gpointer dat
 	 * then just restarting */
 	/* Also we may not need to check ALL those keys but just a few */
 	if ( ! string_same (config, GdmGtkRC, GDM_KEY_GTKRC) ||
+	     ! string_same (config, GdmInfoMsgFile, GDM_KEY_INFO_MSG_FILE) ||
 	     ! int_same (config,
 			 GdmXineramaScreen, GDM_KEY_XINERAMASCREEN) ||
 	     ! bool_same (config, GdmSystemMenu, GDM_KEY_SYSMENU) ||
@@ -3687,6 +3690,42 @@ gdm_reread_config (int sig, gpointer dat
 	return TRUE;
 }

+void
+gdm_login_show_info_msg(void)
+{
+	GtkWidget *dialog, *label;
+	gchar *InfoMsg;
+	gsize InfoMsgLength;
+
+	if (!GdmInfoMsgFile ||
+	    !strlen (GdmInfoMsgFile) ||
+	    !g_file_test (GdmInfoMsgFile, G_FILE_TEST_EXISTS) ||
+	    !g_file_get_contents (GdmInfoMsgFile, &InfoMsg, &InfoMsgLength, NULL) ||
+	    !InfoMsgLength)
+		return;
+
+	gdm_wm_focus_new_windows (TRUE);
+	dialog = gtk_dialog_new_with_buttons (NULL /* Message */,
+			NULL /* parent */, GTK_DIALOG_MODAL |
+			GTK_DIALOG_DESTROY_WITH_PARENT,
+			GTK_STOCK_OK, GTK_RESPONSE_OK,
+			NULL);
+	label = gtk_label_new (InfoMsg);
+
+	gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), label);
+	gtk_widget_show_all (dialog);
+	gdm_wm_center_window (GTK_WINDOW (dialog));
+
+	setup_cursor (GDK_LEFT_PTR);
+
+	gdm_wm_no_login_focus_push();
+	gtk_dialog_run (GTK_DIALOG (dialog));
+	gtk_widget_destroy (dialog);
+	gdm_wm_no_login_focus_pop();
+
+	g_free (InfoMsg);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -4047,6 +4086,8 @@ main (int argc, char *argv[])

     gdm_wm_restore_wm_order ();

+    gdm_login_show_info_msg ();
+
     /* Only setup the cursor now since it will be a WATCH from before */
     setup_cursor (GDK_LEFT_PTR);

diff -urNp gdm-2.4.4.3.old/gui/greeter/greeter.c gdm-2.4.4.3/gui/greeter/greeter.c
--- gdm-2.4.4.3.old/gui/greeter/greeter.c	2003-09-24 20:20:57.000000000 +0100
+++ gdm-2.4.4.3/gui/greeter/greeter.c	2003-09-30 17:52:43.000000000 +0100
@@ -69,6 +69,7 @@ gboolean GdmAllowRoot;
 gboolean GdmAllowRemoteRoot;
 gchar *GdmWelcome;
 gchar *GdmServAuthDir;
+gchar *GdmInfoMsgFile;

 gboolean GdmUseCirclesInEntry = FALSE;

@@ -138,6 +139,7 @@ greeter_parse_config (void)
     GdmConfigurator = ve_config_get_string (config, GDM_KEY_CONFIGURATOR);
     GdmGtkRC = ve_config_get_string (config, GDM_KEY_GTKRC);
     GdmServAuthDir = ve_config_get_string (config, GDM_KEY_SERVAUTH);
+    GdmInfoMsgFile = ve_config_get_string (config, GDM_KEY_INFO_MSG_FILE);

     GdmWelcome = ve_config_get_translated_string (config, greeter_Welcome_key);
     /* A hack! */
@@ -923,6 +925,9 @@ greeter_reread_config (int sig, gpointer
 	     ! string_same (config,
 			    GdmConfigurator,
 			    GDM_KEY_CONFIGURATOR) ||
+	     ! string_same (config,
+			    GdmInfoMsgFile,
+			    GDM_KEY_INFO_MSG_FILE) ||
 	     ! bool_same (config,
 			  GdmConfigAvailable,
 			  GDM_KEY_CONFIG_AVAILABLE) ||
@@ -1114,6 +1119,52 @@ gdm_login_abort (const gchar *format, ..
     _exit (DISPLAY_GREETERFAILED);
 }

+void
+greeter_show_info_msg(void)
+{
+	GtkWidget *dialog, *label;
+	GreeterItemInfo *InfoMsgDlgFmt;
+	gchar *InfoMsg;
+	gsize InfoMsgLength;
+
+	if (!GdmInfoMsgFile ||
+	    !strlen (GdmInfoMsgFile) ||
+	    !g_file_test (GdmInfoMsgFile, G_FILE_TEST_EXISTS) ||
+	    !g_file_get_contents (GdmInfoMsgFile, &InfoMsg, &InfoMsgLength, NULL) ||
+	    !InfoMsgLength)
+		return;
+
+	gdm_wm_focus_new_windows (TRUE);
+	dialog = gtk_dialog_new_with_buttons (NULL /* Message */,
+			NULL /* parent */, GTK_DIALOG_MODAL |
+			GTK_DIALOG_DESTROY_WITH_PARENT,
+			GTK_STOCK_OK, GTK_RESPONSE_OK,
+			NULL);
+	label = gtk_label_new (InfoMsg);
+
+	InfoMsgDlgFmt = greeter_lookup_id ("info-msg-dialog-format");
+	if (InfoMsgDlgFmt) {
+		GdkColor c;
+
+		gtk_widget_modify_font (label, InfoMsgDlgFmt->data.text.fonts[GREETER_ITEM_STATE_NORMAL]);
+		get_gdk_color_from_rgb (&c, InfoMsgDlgFmt->data.text.colors[GREETER_ITEM_STATE_NORMAL]);
+		gtk_widget_modify_text (label, GTK_STATE_NORMAL, &c);
+	}
+
+	gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), label);
+	gtk_widget_show_all (dialog);
+	gdm_wm_center_window (GTK_WINDOW (dialog));
+
+	greeter_setup_cursor (GDK_LEFT_PTR);
+
+	gdm_wm_no_login_focus_push();
+	gtk_dialog_run (GTK_DIALOG (dialog));
+	gtk_widget_destroy (dialog);
+	gdm_wm_no_login_focus_pop();
+
+	g_free (InfoMsg);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -1488,6 +1539,8 @@ main (int argc, char *argv[])

   gdm_wm_restore_wm_order ();

+  greeter_show_info_msg ();
+
   greeter_setup_cursor (GDK_LEFT_PTR);

   gtk_main ();
diff -urNp gdm-2.4.4.3.old/gui/greeter/greeter_canvas_item.c gdm-2.4.4.3/gui/greeter/greeter_canvas_item.c
--- gdm-2.4.4.3.old/gui/greeter/greeter_canvas_item.c	2003-09-25 00:21:10.000000000 +0100
+++ gdm-2.4.4.3/gui/greeter/greeter_canvas_item.c	2003-09-30 17:38:43.000000000 +0100
@@ -164,7 +164,7 @@ make_menubar (void)
 	return menubar;
 }

-static void
+void
 get_gdk_color_from_rgb (GdkColor *c, guint32 rgb)
 {
 	c->red = ((rgb & 0xff0000) >> 16) * 0x101;
diff -urNp gdm-2.4.4.3.old/gui/greeter/greeter_canvas_item.h gdm-2.4.4.3/gui/greeter/greeter_canvas_item.h
--- gdm-2.4.4.3.old/gui/greeter/greeter_canvas_item.h	2003-09-25 00:13:18.000000000 +0100
+++ gdm-2.4.4.3/gui/greeter/greeter_canvas_item.h	2003-09-30 17:39:08.000000000 +0100
@@ -1,6 +1,8 @@
 #ifndef GREETER_CANVAS_ITEM_H
 #define GREETER_CANVAS_ITEM_H

+void get_gdk_color_from_rgb (GdkColor *c, guint32 rgb);
+
 void greeter_item_create_canvas_item (GreeterItemInfo *item);

 void greeter_canvas_item_break_set_string (GreeterItemInfo *info,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]