summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Plattner <aplattner@nvidia.com>2009-10-16 22:55:24 -0700
committerAaron Plattner <aplattner@nvidia.com>2009-10-16 22:55:24 -0700
commitc82cf906728d7772312bb1eed3c24df352f80458 (patch)
tree5c6c50fc130a2f6cfdba4368e8ed773c16fbc9b4
parent83aa418a5c827b1b834cafd0c111c53330f4d64d (diff)
190.40190.40
-rw-r--r--src/XF86Config-parser/Merge.c28
-rw-r--r--src/XF86Config-parser/Module.c40
-rw-r--r--src/XF86Config-parser/xf86Parser.h3
-rw-r--r--src/XF86Config-parser/xf86tokens.h1
-rw-r--r--src/gtk+-2.x/ctkdisplayconfig-utils.c134
-rw-r--r--src/gtk+-2.x/ctkdisplayconfig.c52
-rw-r--r--src/libXNVCtrlAttributes/NvCtrlAttributesNvControl.c13
7 files changed, 162 insertions, 109 deletions
diff --git a/src/XF86Config-parser/Merge.c b/src/XF86Config-parser/Merge.c
index b3614ec..26521ee 100644
--- a/src/XF86Config-parser/Merge.c
+++ b/src/XF86Config-parser/Merge.c
@@ -129,15 +129,11 @@ static int xconfigOptionValuesDiffer(XConfigOptionPtr option0,
*
* Merging here means:
*
- * If the option is not in the source config, remove it from the dest
- * config.
- *
- * If the option is in the source config, make sure the dest config
- * contains the option with the same value as the source config.
- *
- * if "comments" is given, a comment will be added to note when
- * an option has been removed/replaced.
- *
+ * If the option is not in the source config, do nothing to the
+ * destination. Otherwise, either add or update the option in
+ * the dest. If the option is modified, and a comment is given,
+ * then the old option will be commented out instead of being
+ * simply removed/replaced.
*/
static void xconfigMergeOption(XConfigOptionPtr *dstHead,
XConfigOptionPtr *srcHead,
@@ -148,14 +144,14 @@ static void xconfigMergeOption(XConfigOptionPtr *dstHead,
char *srcValue = NULL;
- if (srcOption) srcValue = xconfigOptionValue(srcOption);
-
- if (!srcOption && dstOption) {
+ if (!srcOption) {
+ /* Option does not exist in src, do nothing to dst. */
+ return;
+ }
- /* option does not exist in src, but exists in dst: remove from dst */
- xconfigRemoveOption(dstHead, dstOption);
+ srcValue = xconfigOptionValue(srcOption);
- } else if (srcOption && !dstOption) {
+ if (srcOption && !dstOption) {
/* option exists in src but not in dst: add to dst */
xconfigAddNewOption(dstHead, name, srcValue);
@@ -714,7 +710,7 @@ static int xconfigMergeLayout(XConfigPtr dstConfig, XConfigPtr srcConfig)
*/
int xconfigMergeConfigs(XConfigPtr dstConfig, XConfigPtr srcConfig)
{
- /* Make sure the X config is falid */
+ /* Make sure the X config is valid */
// make_xconfig_usable(dstConfig);
diff --git a/src/XF86Config-parser/Module.c b/src/XF86Config-parser/Module.c
index 69dde1a..042a409 100644
--- a/src/XF86Config-parser/Module.c
+++ b/src/XF86Config-parser/Module.c
@@ -73,6 +73,7 @@ static XConfigSymTabRec ModuleTab[] =
{ENDSECTION, "endsection"},
{LOAD, "load"},
{LOAD_DRIVER, "loaddriver"},
+ {DISABLE, "disable"},
{SUBSECTION, "subsection"},
{-1, ""},
};
@@ -143,6 +144,12 @@ xconfigParseModuleSection (void)
xconfigAddNewLoadDirective (&ptr->loads, val.str,
XCONFIG_LOAD_DRIVER, NULL, TRUE);
break;
+ case DISABLE:
+ if (xconfigGetSubToken (&(ptr->comment)) != STRING)
+ Error (QUOTE_MSG, "Disable");
+ xconfigAddNewLoadDirective (&ptr->disables, val.str,
+ XCONFIG_DISABLE_MODULE, NULL, TRUE);
+ break;
case SUBSECTION:
if (xconfigGetSubToken (&(ptr->comment)) != STRING)
Error (QUOTE_MSG, "SubSection");
@@ -208,6 +215,19 @@ xconfigPrintModuleSection (FILE * cf, XConfigModulePtr ptr)
#endif
}
}
+ for (lptr = ptr->disables; lptr; lptr = lptr->next)
+ {
+ switch (lptr->type)
+ {
+ case XCONFIG_DISABLE_MODULE:
+ fprintf (cf, " Disable \"%s\"", lptr->name);
+ if (lptr->comment)
+ fprintf(cf, "%s", lptr->comment);
+ else
+ fputc('\n', cf);
+ break;
+ }
+ }
}
void
@@ -245,16 +265,11 @@ xconfigRemoveLoadDirective(XConfigLoadPtr *pHead, XConfigLoadPtr load)
free(load);
}
-void
-xconfigFreeModules (XConfigModulePtr *ptr)
+static void
+FreeModule(XConfigLoadPtr lptr)
{
- XConfigLoadPtr lptr;
XConfigLoadPtr prev;
- if (ptr == NULL || *ptr == NULL)
- return;
-
- lptr = (*ptr)->loads;
while (lptr)
{
TEST_FREE (lptr->name);
@@ -263,6 +278,17 @@ xconfigFreeModules (XConfigModulePtr *ptr)
lptr = lptr->next;
free (prev);
}
+}
+
+void
+xconfigFreeModules (XConfigModulePtr *ptr)
+{
+ if (ptr == NULL || *ptr == NULL)
+ return;
+
+ FreeModule((*ptr)->loads);
+ FreeModule((*ptr)->disables);
+
TEST_FREE ((*ptr)->comment);
free (*ptr);
*ptr = NULL;
diff --git a/src/XF86Config-parser/xf86Parser.h b/src/XF86Config-parser/xf86Parser.h
index 2e1e7b4..3369725 100644
--- a/src/XF86Config-parser/xf86Parser.h
+++ b/src/XF86Config-parser/xf86Parser.h
@@ -169,7 +169,7 @@ typedef struct {
/* Values for load_type */
#define XCONFIG_LOAD_MODULE 0
#define XCONFIG_LOAD_DRIVER 1
-
+#define XCONFIG_DISABLE_MODULE 2
/*
@@ -186,6 +186,7 @@ typedef struct __xconfigloadrec {
typedef struct {
XConfigLoadPtr loads;
+ XConfigLoadPtr disables;
char *comment;
} XConfigModuleRec, *XConfigModulePtr;
diff --git a/src/XF86Config-parser/xf86tokens.h b/src/XF86Config-parser/xf86tokens.h
index 1189bc0..d44dcbf 100644
--- a/src/XF86Config-parser/xf86tokens.h
+++ b/src/XF86Config-parser/xf86tokens.h
@@ -167,6 +167,7 @@ typedef enum {
/* Module tokens */
LOAD,
LOAD_DRIVER,
+ DISABLE,
/* Device tokens */
DRIVER,
diff --git a/src/gtk+-2.x/ctkdisplayconfig-utils.c b/src/gtk+-2.x/ctkdisplayconfig-utils.c
index e91f9a3..80b1067 100644
--- a/src/gtk+-2.x/ctkdisplayconfig-utils.c
+++ b/src/gtk+-2.x/ctkdisplayconfig-utils.c
@@ -2845,6 +2845,35 @@ static int save_xconfig_file(SaveXConfDlg *dlg,
+/** get_non_regular_file_type_description() **************************
+ *
+ * Returns a string that describes the mode type of a file.
+ *
+ */
+static const char *get_non_regular_file_type_description(mode_t mode)
+{
+ if (S_ISDIR(mode)) {
+ return "directory";
+ } else if (S_ISCHR(mode)) {
+ return "character device file";
+ } else if (S_ISBLK(mode)) {
+ return "block device file";
+ } else if (S_ISFIFO(mode)) {
+ return "FIFO";
+ } else if (S_ISLNK(mode)) {
+ return "symbolic link";
+ } else if (S_ISSOCK(mode)) {
+ return "socket";
+ } else if (!S_ISREG(mode)) {
+ return "non-regular file";
+ }
+
+ return NULL;
+
+} /* get_non_regular_file_type_description() */
+
+
+
/** update_xconfig_save_buffer() ************************************
*
* Updates the "preview" buffer to hold the right contents based on
@@ -2871,7 +2900,7 @@ static void update_xconfig_save_buffer(SaveXConfDlg *dlg)
gboolean merge;
gboolean merged;
- gboolean merge_error;
+ gboolean mergeable = FALSE;
gchar *err_msg = NULL;
@@ -2883,17 +2912,34 @@ static void update_xconfig_save_buffer(SaveXConfDlg *dlg)
filename = (gchar *)gtk_entry_get_text(GTK_ENTRY(dlg->txt_xconfig_file));
+
+ /* Assume we can save until we find out otherwise */
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(dlg->dlg_xconfig_save),
+ GTK_RESPONSE_ACCEPT,
+ TRUE);
+
+
/* Find out if the file is mergable */
- if (filename && (filename[0] != '\0')) {
+ if (filename && (stat(filename, &st) == 0)) {
+ const char *non_regular_file_type_description =
+ get_non_regular_file_type_description(st.st_mode);
+
+ /* Make sure this is a regular file */
+ if (non_regular_file_type_description) {
+ err_msg = g_strdup_printf("Invalid file '%s': File exits but is a "
+ "%s!",
+ filename,
+ non_regular_file_type_description);
+ gtk_widget_set_sensitive(dlg->btn_xconfig_merge, FALSE);
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(dlg->dlg_xconfig_save),
+ GTK_RESPONSE_ACCEPT,
+ FALSE);
+ goto fail;
+ }
+
/* Must be able to open the file */
tmp_filename = (char *)xconfigOpenConfigFile(filename, NULL);
if (!tmp_filename || strcmp(tmp_filename, filename)) {
- err_msg = g_strdup_printf("Failed to open existing X config "
- "file '%s'!",
- filename);
- ctk_display_warning_msg
- (ctk_get_parent_window(GTK_WIDGET(dlg->parent)), err_msg);
-
xconfigCloseConfigFile();
} else {
@@ -2913,42 +2959,47 @@ static void update_xconfig_save_buffer(SaveXConfDlg *dlg)
(ctk_get_parent_window(GTK_WIDGET(dlg->parent)), err_msg);
xconfCur = NULL;
- }
- /* Sanitize the X config file */
- xconfigGenerateLoadDefaultOptions(&gop);
- xconfigGetXServerInUse(&gop);
+ } else {
- if (!xconfigSanitizeConfig(xconfCur, NULL, &gop)) {
- err_msg = g_strdup_printf("Failed to sanitize existing X "
- "config file '%s'!",
- filename);
- ctk_display_warning_msg
- (ctk_get_parent_window(GTK_WIDGET(dlg->parent)), err_msg);
+ /* Sanitize the X config file */
+ xconfigGenerateLoadDefaultOptions(&gop);
+ xconfigGetXServerInUse(&gop);
+
+ if (!xconfigSanitizeConfig(xconfCur, NULL, &gop)) {
+ err_msg = g_strdup_printf("Failed to sanitize existing X "
+ "config file '%s'!",
+ filename);
+ ctk_display_warning_msg
+ (ctk_get_parent_window(GTK_WIDGET(dlg->parent)),
+ err_msg);
+
+ xconfigFreeConfig(&xconfCur);
+ xconfCur = NULL;
+ } else {
+ mergeable = TRUE;
+ }
+ }
+ /* If we're not actualy doing a merge, close the file */
+ if (!merge && xconfCur) {
xconfigFreeConfig(&xconfCur);
- xconfCur = NULL;
}
}
-
- /* If we're not actualy doing a merge, close the file */
- if (!merge && xconfCur) {
- xconfigFreeConfig(&xconfCur);
- }
}
- merge_error = merge && !xconfCur;
- merge = (merge && !merge_error);
-
- /* If we have to merge but we can't, report the problem. */
- if (merge_error && !dlg->merge_toggleable) {
- // XXX Instead of bailing here, we may want to just disable
- // the "Save" button until the user specifies a file
- // that we can parse.
+ /* If we have to merge but we cannot, prevent user from saving */
+ if (merge && !xconfCur && !dlg->merge_toggleable) {
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(dlg->dlg_xconfig_save),
+ GTK_RESPONSE_ACCEPT,
+ FALSE);
goto fail;
}
+ merge = (merge && xconfCur);
+
+
/* Generate the X config file */
xconfGen = dlg->xconf_gen_func(xconfCur, merge, &merged,
dlg->callback_data);
@@ -2957,8 +3008,6 @@ static void update_xconfig_save_buffer(SaveXConfDlg *dlg)
goto fail;
}
- merge_error = merge && !merged;
-
/* Update merge status */
g_signal_handlers_block_by_func
(G_OBJECT(dlg->btn_xconfig_merge),
@@ -2972,7 +3021,7 @@ static void update_xconfig_save_buffer(SaveXConfDlg *dlg)
G_CALLBACK(xconfig_update_buffer), (gpointer) dlg);
gtk_widget_set_sensitive(dlg->btn_xconfig_merge,
- (dlg->merge_toggleable && !merge_error) ?
+ (dlg->merge_toggleable && mergeable) ?
TRUE : FALSE);
@@ -3162,6 +3211,7 @@ void run_save_xconfig_dialog(SaveXConfDlg *dlg)
GtkTextIter buf_start, buf_end;
gchar *filename;
gchar *tmp_filename;
+ struct stat st;
gint result;
@@ -3199,6 +3249,20 @@ void run_save_xconfig_dialog(SaveXConfDlg *dlg)
filename = g_strdup(tmp_filename);
}
+ /* If the file exists, make sure it is a regular file */
+ if (stat(filename, &st) == 0) {
+ const char *non_regular_file_type_description =
+ get_non_regular_file_type_description(st.st_mode);
+
+ if (non_regular_file_type_description) {
+ nv_error_msg("Failed to write X configuration to file '%s': "
+ "File exists but is a %s.",
+ filename,
+ non_regular_file_type_description);
+ break;
+ }
+ }
+
/* Get the buffer to write */
gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(dlg->buf_xconfig_save),
&buf_start, &buf_end);
diff --git a/src/gtk+-2.x/ctkdisplayconfig.c b/src/gtk+-2.x/ctkdisplayconfig.c
index 0a9d923..8fd8bba 100644
--- a/src/gtk+-2.x/ctkdisplayconfig.c
+++ b/src/gtk+-2.x/ctkdisplayconfig.c
@@ -7158,11 +7158,7 @@ static Bool add_layout_to_xconfig(nvLayoutPtr layout, XConfigPtr config)
/* Setup for Xinerama */
- if (!config->flags) {
- config->flags = (XConfigFlagsPtr) calloc(1, sizeof(XConfigFlagsRec));
- if (!config->flags) goto fail;
- }
- xconfigAddNewOption(&config->flags->options, "Xinerama",
+ xconfigAddNewOption(&conf_layout->options, "Xinerama",
(layout->xinerama_enabled ? "1" : "0"));
layout->conf_layout = conf_layout;
@@ -7176,39 +7172,6 @@ static Bool add_layout_to_xconfig(nvLayoutPtr layout, XConfigPtr config)
/*
- * get_default_project_root() - scan some common directories for the X
- * project root
- *
- * Users of this information should be careful to account for the
- * modular layout.
- */
-
-char *get_default_project_root(void)
-{
- char *paths[] = { "/usr/X11R6", "/usr/X11", NULL };
- struct stat stat_buf;
- int i;
-
- for (i = 0; paths[i]; i++) {
-
- if (stat(paths[i], &stat_buf) == -1) {
- continue;
- }
-
- if (S_ISDIR(stat_buf.st_mode)) {
- return paths[i];
- }
- }
-
- /* default to "/usr/X11R6", I guess */
-
- return paths[0];
-
-} /* get_default_project_root() */
-
-
-
-/*
* generateXConfig() - Generates an X config structure based
* on the layout given.
*/
@@ -7225,7 +7188,11 @@ static int generateXConfig(CtkDisplayConfig *ctk_object, XConfigPtr *pConfig)
if (!pConfig) goto fail;
- /* Query server X.Org/XFree86 */
+ /* XXX Assume we are creating an X config file for the local system */
+ xconfigGenerateLoadDefaultOptions(&go);
+ xconfigGetXServerInUse(&go);
+
+ /* Query actual server X.Org/XFree86 */
server_vendor = NvCtrlGetServerVendor(layout->handle);
if (server_vendor && g_strrstr(server_vendor, "X.Org")) {
go.xserver = X_IS_XORG;
@@ -7234,13 +7201,6 @@ static int generateXConfig(CtkDisplayConfig *ctk_object, XConfigPtr *pConfig)
}
- /* XXX Assume we are creating an X config file for the local system */
- go.x_project_root = get_default_project_root();
- go.keyboard = NULL;
- go.mouse = NULL;
- go.keyboard_driver = NULL;
-
-
/* Generate the basic layout */
config = xconfigGenerate(&go);
diff --git a/src/libXNVCtrlAttributes/NvCtrlAttributesNvControl.c b/src/libXNVCtrlAttributes/NvCtrlAttributesNvControl.c
index 727d605..28891c2 100644
--- a/src/libXNVCtrlAttributes/NvCtrlAttributesNvControl.c
+++ b/src/libXNVCtrlAttributes/NvCtrlAttributesNvControl.c
@@ -185,13 +185,18 @@ ReturnStatus NvCtrlNvControlSetAttribute (NvCtrlAttributePrivateHandle *h,
unsigned int display_mask,
int attr, int val)
{
+ Bool bRet;
+
if (attr <= NV_CTRL_LAST_ATTRIBUTE) {
- XNVCTRLSetTargetAttribute (h->dpy, h->target_type, h->target_id,
- display_mask, attr, val);
- XFlush (h->dpy);
+ bRet = XNVCTRLSetTargetAttributeAndGetStatus (h->dpy, h->target_type,
+ h->target_id,
+ display_mask, attr, val);
+ if (!bRet) {
+ return NvCtrlError;
+ }
return NvCtrlSuccess;
}
-
+
return NvCtrlNoAttribute;
} /* NvCtrlNvControlSetAttribute() */