Пример #1
0
			if (call_func) {			\
				error_msg (err_msg);		\
					applet->error = err_val;\
						break;		\
			}

#	define FINISH_INIT()					\
		applet->error = ERR_OK;				\
		case ERR_OK:

#	define END_INIT()					\
		return; }

	START_INIT()

	TRY_INIT (!ddcci_init (NULL),
		ERR_DDCCI_INIT,
		_("Unable to initialize ddcci library"))
		
	TRY_INIT (!fill_monitor_combo (applet),
		ERR_FILL_MONITOR_COMBO,
		_("No monitor configuration found."
		 " Please run gddccontrol first"))
	
	TRY_INIT (ddcci_open (applet->monitor, applet->monitor_name , 0) < 0,
		ERR_DDCCI_OPEN,
		_("An error occurred while"
		 " opening the monitor device"))

	TRY_INIT (!fill_profiles_menu (applet),
		ERR_FILL_PROFILES_MENU,
Пример #2
0
int main( int   argc, char *argv[] )
{ 
	int i, verbosity = 0;
	
	mon = NULL;
	monitor_manager = NULL;
	
#ifdef HAVE_GETTEXT
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	bindtextdomain("ddccontrol-db", LOCALEDIR);
	bind_textdomain_codeset(PACKAGE, "UTF-8");
	bind_textdomain_codeset("ddccontrol-db", "UTF-8");
	textdomain(PACKAGE);
#endif

	while ((i=getopt(argc,argv,"v")) >= 0)
	{
		switch(i) {
		case 'v':
			verbosity++;
			break;
		}
	}
	
	ddcci_verbosity(verbosity);
	
	gtk_init(&argc, &argv);
	
	g_thread_init(NULL);
	combo_change_mutex = g_mutex_new();
	
	tooltips = gtk_tooltips_new();
	
	/* Full screen patterns test */
	/*create_fullscreen_patterns_window();
	show_pattern();
	gtk_main();*/
	
	if (!ddcci_init(NULL)) {
		printf(_("Unable to initialize ddcci library.\n"));
		GtkWidget* dialog = gtk_message_dialog_new(
				GTK_WINDOW(main_app_window),
				GTK_DIALOG_DESTROY_WITH_PARENT,
				GTK_MESSAGE_ERROR,
				GTK_BUTTONS_CLOSE,
				_("Unable to initialize ddcci library, see console for more details.\n"));
		gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);
		return 1;
	}
	
	g_timeout_add( IDLE_TIMEOUT*1000, heartbeat, NULL );
	
	main_app_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	
	gtk_window_set_title(GTK_WINDOW(main_app_window),_("Monitor settings"));
	
	gtk_window_set_default_size(GTK_WINDOW(main_app_window), 500, 500);

	gtk_window_set_position (GTK_WINDOW (main_app_window), GTK_WIN_POS_CENTER);
	
	g_signal_connect (G_OBJECT (main_app_window), "delete_event",
				G_CALLBACK (delete_event), NULL);
	
	g_signal_connect (G_OBJECT (main_app_window), "destroy",
				G_CALLBACK (destroy), NULL);

	g_signal_connect (G_OBJECT (main_app_window), "configure-event",
				G_CALLBACK (window_changed), NULL);
	
	gtk_container_set_border_width (GTK_CONTAINER (main_app_window), 4);
	
	table = gtk_table_new(5, 1, FALSE);
	gtk_widget_show (table);
	int crow = 0; /* Current row */
	
	/* Monitor choice combo box */
	choice_hbox = gtk_hbox_new(FALSE, 10);
	
	GtkWidget* label = gtk_label_new(_("Current monitor: "));
	gtk_widget_show(label);
	gtk_box_pack_start(GTK_BOX(choice_hbox),label, 0, 0, 0);
	
	combo_box = gtk_combo_box_new_text();
	
	gtk_widget_show(combo_box);

	gtk_box_pack_start(GTK_BOX(choice_hbox),combo_box, 1, 1, 0);
	
	refresh_monitors_button = stock_label_button(GTK_STOCK_REFRESH, NULL, _("Refresh monitor list"));
	g_signal_connect(G_OBJECT(refresh_monitors_button), "clicked", G_CALLBACK(probe_monitors), NULL);
	gtk_widget_show(refresh_monitors_button);
	gtk_box_pack_start(GTK_BOX(choice_hbox),refresh_monitors_button, 0, 0, 0);
	
	gtk_table_attach(GTK_TABLE(table), choice_hbox, 0, 1, crow, crow+1, GTK_FILL_EXPAND, 0, 5, 5);
	crow++;
	gtk_widget_show(choice_hbox);
	
	GtkWidget* hsep = gtk_hseparator_new();
	gtk_widget_show (hsep);
	gtk_table_attach(GTK_TABLE(table), hsep, 0, 1, crow, crow+1, GTK_FILL_EXPAND, GTK_SHRINK, 0, 0);
	crow++;
	
	/* Toolbar (profile...) */
	profile_hbox = gtk_hbox_new(FALSE, 10);
	
	profile_manager_button = stock_label_button(GTK_STOCK_OPEN, _("Profile manager"), NULL);
	g_signal_connect(G_OBJECT(profile_manager_button), "clicked", G_CALLBACK(loadprofile_callback), NULL);

	gtk_box_pack_start(GTK_BOX(profile_hbox), profile_manager_button, 0, 0, 0);
	gtk_widget_show (profile_manager_button);
	gtk_widget_set_sensitive(profile_manager_button, FALSE);
	
	saveprofile_button = stock_label_button(GTK_STOCK_SAVE, _("Save profile"), NULL);
	g_signal_connect(G_OBJECT(saveprofile_button), "clicked", G_CALLBACK(saveprofile_callback), NULL);

	gtk_box_pack_start(GTK_BOX(profile_hbox), saveprofile_button, 0, 0, 0);
	gtk_widget_set_sensitive(saveprofile_button, FALSE);
	
	cancelprofile_button = stock_label_button(GTK_STOCK_SAVE, _("Cancel profile creation"), NULL);
	g_signal_connect(G_OBJECT(cancelprofile_button), "clicked", G_CALLBACK(cancelprofile_callback), NULL);

	gtk_box_pack_start(GTK_BOX(profile_hbox), cancelprofile_button, 0, 0, 0);
	gtk_widget_set_sensitive(cancelprofile_button, FALSE);
	
	gtk_widget_show (profile_hbox);
	gtk_table_attach(GTK_TABLE(table), profile_hbox, 0, 1, crow, crow+1, GTK_FILL_EXPAND, GTK_SHRINK, 8, 8);
	crow++;
	
	hsep = gtk_hseparator_new();
	gtk_widget_show (hsep);
	gtk_table_attach(GTK_TABLE(table), hsep, 0, 1, crow, crow+1, GTK_FILL_EXPAND, GTK_SHRINK, 0, 0);
	crow++;
	
	/* Status message label (used when loading or refreshing, or when displaying some kind of warnings) */
	messagebox = gtk_vbox_new(FALSE, 10);
	
	messagelabel = gtk_label_new ("");
	gtk_label_set_line_wrap(GTK_LABEL(messagelabel), TRUE);
	gtk_box_pack_start(GTK_BOX(messagebox), messagelabel, 1, 1, 0);
	gtk_widget_show(messagelabel);
	
	GtkWidget* messagealign = gtk_alignment_new(0.5, 0.5, 0, 0);
	messagebutton = stock_label_button(GTK_STOCK_OK, _("OK"), NULL);
	g_signal_connect(G_OBJECT(messagebutton), "clicked", G_CALLBACK(messagebutton_callback), NULL);
	gtk_container_add(GTK_CONTAINER(messagealign), messagebutton);
	gtk_widget_show(messagebutton);
	
	gtk_box_pack_start(GTK_BOX(messagebox), messagealign, 0, 0, 10);
	gtk_widget_show(messagealign);
	
	gtk_table_attach(GTK_TABLE(table), messagebox, 0, 1, crow, crow+1, GTK_FILL_EXPAND, GTK_FILL_EXPAND, 5, 5);
	mainrow = crow;
	crow++;
	
	hsep = gtk_hseparator_new();
	gtk_widget_show (hsep);
	gtk_table_attach(GTK_TABLE(table), hsep, 0, 1, crow, crow+1, GTK_FILL_EXPAND, GTK_SHRINK, 0, 0);
	crow++;
	
	/* Refresh and close buttons */
	bottom_hbox = gtk_hbox_new(FALSE, 10);
	
	statuslabel = gtk_label_new("");
	gtk_label_set_line_wrap(GTK_LABEL(statuslabel), TRUE);
	gtk_box_pack_start(GTK_BOX(bottom_hbox),statuslabel, TRUE, TRUE, 0);
	gtk_widget_show(statuslabel);
	
	GtkWidget* align = gtk_alignment_new(1, 0.5, 0, 0);
	GtkWidget* br_hbox = gtk_hbox_new(FALSE, 30);
	
	refresh_controls_button = stock_label_button(GTK_STOCK_REFRESH, _("Refresh"), _("Refresh all controls"));
	g_signal_connect(G_OBJECT(refresh_controls_button),"clicked",G_CALLBACK (refresh_all_controls), NULL);

	gtk_box_pack_start(GTK_BOX(br_hbox),refresh_controls_button,0,0,0);
	gtk_widget_show (refresh_controls_button);
	gtk_widget_set_sensitive(refresh_controls_button, FALSE);
	
	close_button = stock_label_button(GTK_STOCK_CLOSE, _("Close"), NULL);
	g_signal_connect(G_OBJECT(close_button),"clicked",G_CALLBACK (destroy), NULL);

	gtk_box_pack_start(GTK_BOX(br_hbox),close_button,0,0,0);
	gtk_widget_show (close_button);
	
	gtk_container_add(GTK_CONTAINER(align),br_hbox);
	gtk_widget_show (br_hbox);
	gtk_widget_show (align);
	
	gtk_box_pack_start(GTK_BOX(bottom_hbox),align, TRUE, TRUE,0);
	gtk_widget_show (bottom_hbox);
	gtk_table_attach(GTK_TABLE(table), bottom_hbox, 0, 1, crow, crow+1, GTK_FILL_EXPAND, GTK_SHRINK, 8, 8);
	crow++;
	
	gtk_container_add (GTK_CONTAINER(main_app_window), table);
	
	gtk_widget_show(main_app_window);
	
	GdkScreen* screen = gdk_screen_get_default();
	
	num_monitor = gdk_screen_get_n_monitors(screen);
	
	/*for (i = 0; i < nscreen; i++) {
		GdkRectangle dest;
		
		gdk_screen_get_monitor_geometry(screen, i, &dest);
		printf("%d: %d, %d %dx%d\n", nscreen, dest.x, dest.y, dest.width, dest.height);
	}*/
	
	current_monitor = gdk_screen_get_monitor_at_window(screen, main_app_window->window);
	
	probe_monitors(NULL, NULL);
	
/*	moninfo = gtk_label_new ();
	gtk_misc_set_alignment(GTK_MISC(moninfo), 0, 0);
	
	gtk_table_attach(GTK_TABLE(table), moninfo, 0, 1, 1, 2, GTK_FILL_EXPAND, 0, 5, 5);*/
	
	gchar* tmp = g_strdup_printf(_("Welcome to gddccontrol %s."), VERSION);
	set_status(tmp);
	g_free(tmp);
	
	gtk_main();
	
	delete_monitor_manager();
	
	ddcci_free_list(monlist);
	
	ddcci_release();
	
	return 0;
}
Пример #3
0
int main(int argc, char **argv)
{
    int i, retry, ret;

    /* filedescriptor and name of device */
    struct monitor mon;
    char *fn;

    char *datadir = NULL;
    char *pnpname = NULL; /* pnpname for -i parameter */

    /* what to do */
    int dump = 0;
    int ctrl = -1;
    int value = -1;
    int caps = 0;
    int save = 0;
    int force = 0;
    int verbosity = 0;
    int probe = 0;

#ifdef HAVE_GETTEXT
    setlocale(LC_ALL, "");
    bindtextdomain(PACKAGE, LOCALEDIR);
    bindtextdomain("ddccontrol-db", LOCALEDIR);
    textdomain(PACKAGE);
#endif

    fprintf(stdout,
            _("ddccontrol version %s\n"
              "Copyright 2004-2005 Oleg I. Vdovikin ([email protected])\n"
              "Copyright 2004-2006 Nicolas Boichat ([email protected])\n"
              "This program comes with ABSOLUTELY NO WARRANTY.\n"
              "You may redistribute copies of this program under the terms of the GNU General Public License.\n\n"), VERSION);

    while ((i=getopt(argc,argv, "hdr:w:csfvpb:i:")) >= 0)
    {
        switch(i) {
        case 'h':
            usage(argv[0]);
            exit(1);
            break;
        case 'b':
            datadir = optarg;
            break;
        case 'r':
            if ((ctrl = strtol(optarg, NULL, 0)) < 0 || (ctrl > 255))
            {
                fprintf(stderr,_("'%s' does not seem to be a valid register name\n"), optarg);
                exit(1);
            }
            break;
        case 'w':
            if (ctrl == -1) {
                fprintf(stderr,_("You cannot use -w parameter without -r.\n"));
                exit(1);
            }
            if ((value = strtol(optarg, NULL, 0)) < 0 || (value > 65535))
            {
                fprintf(stderr,_("'%s' does not seem to be a valid value.\n"), optarg);
                exit(1);
            }
            break;
        case 'c':
            caps++;
            break;
        case 'd':
            dump++;
            break;
        case 's':
            save++;
            break;
        case 'f':
            force++;
            break;
        case 'v':
            verbosity++;
            break;
        case 'p':
            probe++;
            break;
        case 'i': /* Undocumented developer parameter: check integrity of a specific EDID id */
            pnpname = optarg;
            break;
        }
    }

    ddcci_verbosity(verbosity);
    if (pnpname) {
        check_integrity(datadir, pnpname);
    }

    if ((optind == argc) && (!probe)) /* Nor device, nor probe option specified. */
    {
        usage(argv[0]);
        exit(1);
    }
    else if ((optind != argc) && (probe)) /* Device and probe option specified. */
    {
        usage(argv[0]);
        exit(1);
    }

    if (!ddcci_init(datadir)) {
        printf(_("Unable to initialize ddcci library.\n"));
        exit(1);
    }

    if (probe) {
        fn = NULL;

        struct monitorlist* monlist;
        struct monitorlist* current;

        monlist = ddcci_probe();

        printf(_("Detected monitors :\n"));

        current = monlist;
        while (current != NULL)
        {
            printf(_(" - Device: %s\n"), current->filename);
            printf(_("   DDC/CI supported: %s\n"), current->supported ? _("Yes") : _("No"));
            printf(_("   Monitor Name: %s\n"), current->name);
            printf(_("   Input type: %s\n"), current->digital ? _("Digital") : _("Analog"));

            if ((!fn) && (current->supported))
            {
                printf(_("  (Automatically selected)\n"));
                fn = malloc(strlen(current->filename)+1);
                strcpy(fn, current->filename);
            }

            current = current->next;
        }

        if (fn == NULL) {
            fprintf(stderr, _(
                        "No monitor supporting DDC/CI available.\n"
                        "If your graphics card need it, please check all the required kernel modules are loaded (i2c-dev, and your framebuffer driver).\n"
                    ));
            ddcci_release();
            exit(0);
        }

        ddcci_free_list(monlist);
    }
    else {
        fn = argv[optind];
    }

    fprintf(stdout, _("Reading EDID and initializing DDC/CI at bus %s...\n"), fn);

    if ((ret = ddcci_open(&mon, fn, 0)) < 0) {
        fprintf(stderr, _(
                    "\nDDC/CI at %s is unusable (%d).\n"
                    "If your graphics card need it, please check all the required kernel modules are loaded (i2c-dev, and your framebuffer driver).\n"
                ), fn, ret);
    } else {
        fprintf(stdout, _("\nEDID readings:\n"));
        fprintf(stdout, _("\tPlug and Play ID: %s [%s]\n"),
                mon.pnpid, mon.db ? mon.db->name : NULL);
        fprintf(stdout, _("\tInput type: %s\n"), mon.digital ? _("Digital") : _("Analog"));

        if (mon.fallback) {
            /* Put a big warning (in red if we are writing to a terminal). */
            printf("%s%s\n", isatty(1) ? "\x1B[5;31m" : "", _("=============================== WARNING ==============================="));
            if (mon.fallback == 1) {
                printf(_(
                           "There is no support for your monitor in the database, but ddccontrol is\n"
                           "using a generic profile for your monitor's manufacturer. Some controls\n"
                           "may not be supported, or may not work as expected.\n"));
            }
            else if (mon.fallback == 2) {
                printf(_(
                           "There is no support for your monitor in the database, but ddccontrol is\n"
                           "using a basic generic profile. Many controls will not be supported, and\n"
                           "some controls may not work as expected.\n"));
            }
            printf(_(
                       "Please update ddccontrol-db, or, if you are already using the latest\n"
                       "version, please send the output of the following command to\n"
                       "[email protected]:\n"));
            printf("\nLANG= LC_ALL= ddccontrol -p -c -d\n\n");
            printf(_("Thank you.\n"));
            printf("%s%s\n", _("=============================== WARNING ==============================="), isatty(1) ? "\x1B[0m" : "");
        }

        if (caps) {
            fprintf(stdout, _("\nCapabilities:\n"));

            for (retry = RETRYS; retry; retry--) {
                if (ddcci_caps(&mon) >= 0) {
                    fprintf(stdout, _("Raw output: %s\n"), mon.caps.raw_caps);

                    fprintf(stdout, _("Parsed output: \n"));
                    fprintf(stdout, "\tVCP: ");
                    int i;
                    for (i = 0; i < 256; i++) {
                        if (mon.caps.vcp[i]) {
                            printf("%02x ", i);
                        }
                    }
                    printf("\n");
                    printf(_("\tType: "));
                    switch(mon.caps.type) {
                    case lcd:
                        printf(_("LCD"));
                        break;
                    case crt:
                        printf(_("CRT"));
                        break;
                    case unk:
                        printf(_("Unknown"));
                        break;
                    }
                    printf("\n");
                    break;
                }
            }

            if (retry == 0) {
                fprintf(stderr, _("Capabilities read fail.\n"));
            }
        }

        if (ctrl >= 0) {
            if (value >= 0) {
                int delay = find_write_delay(&mon, ctrl);
                if (delay >= 0) {
                    fprintf(stdout, _("\nWriting 0x%02x, 0x%02x(%d) (%dms delay)...\n"),
                            ctrl, value, value, delay);
                }
                else {
                    fprintf(stdout, _("\nWriting 0x%02x, 0x%02x(%d)...\n"),
                            ctrl, value, value);
                }
                ddcci_writectrl(&mon, ctrl, value, delay);
            } else {
                fprintf(stdout, _("\nReading 0x%02x...\n"), ctrl);
            }

            dumpctrl(&mon, ctrl, 1);
        }

        if (dump) {
            fprintf(stdout, _("\nControls (valid/current/max) [Description - Value name]:\n"));

            for (i = 0; i < 256; i++) {
                dumpctrl(&mon, i, force);
            }
        }
        else if (ctrl == -1 && caps == 0)
        {
            struct monitor_db* monitor = mon.db;
            struct group_db* group;
            struct subgroup_db* subgroup;
            struct control_db* control;
            struct value_db* valued;

            if (monitor) {
                printf("\n= %s\n", monitor->name);

                for (group = monitor->group_list; group != NULL; group = group->next) {
                    printf("> %s\n", group->name);

                    for (subgroup = group->subgroup_list; subgroup != NULL; subgroup = subgroup->next) {
                        printf("\t> %s\n", subgroup->name);

                        for (control = subgroup->control_list; control != NULL; control = control->next) {
                            printf(_("\t\t> id=%s, name=%s, address=%#x, delay=%dms, type=%d\n"),
                                   control->id, control->name, control->address, control->delay, control->type);

                            valued = control->value_list;
                            if (valued) {
                                printf(_("\t\t  Possible values:\n"));
                            }

                            for (; valued != NULL; valued = valued->next) {
                                printf(_("\t\t\t> id=%s - name=%s, value=%d\n"), valued->id, valued->name, valued->value);
                            }

                            for (retry = RETRYS; retry; retry--) {
                                int result;
                                unsigned short value, maximum;

                                if ((result = ddcci_readctrl(&mon, control->address, &value, &maximum)) >= 0) {
                                    printf(
                                        (result > 0)
                                        ? _("\t\t  supported, value=%d, maximum=%d\n")
                                        : _("\t\t  not supported, value=%d, maximum=%d\n"), value, maximum);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }

        if (save) {
            fprintf(stdout, _("\nSaving settings...\n"));

            ddcci_save(&mon);
        }
    }

    ddcci_close(&mon);

    if (probe) {
        free(fn);
    }

    ddcci_release();
    exit(0);
}