Beispiel #1
0
void
ScreenMode::UpdateOriginalModes()
{
	BScreen screen(fWindow);
	for (int32 workspace = 0; workspace < count_workspaces(); workspace++) {
		if (screen.GetMode(workspace, &fOriginalDisplayMode[workspace]) == B_OK) {
			Get(fOriginal[workspace], workspace);
			fUpdatedModes = true;
		}
	}
}
void
ScreenWindow::_Apply()
{
	// make checkpoint, so we can undo these changes
	fUndoScreenMode.UpdateOriginalModes();

	status_t status = fScreenMode.Set(fSelected);
	if (status == B_OK) {
		// use the mode that has eventually been set and
		// thus we know to be working; it can differ from
		// the mode selected by user due to hardware limitation
		display_mode newMode;
		BScreen screen(this);
		screen.GetMode(&newMode);

		if (fAllWorkspacesItem->IsMarked()) {
			int32 originatingWorkspace = current_workspace();
			for (int32 i = 0; i < count_workspaces(); i++) {
				if (i != originatingWorkspace)
					screen.SetMode(i, &newMode, true);
			}
			fBootWorkspaceApplied = true;
		} else {
			if (current_workspace() == 0)
				fBootWorkspaceApplied = true;
		}

		fActive = fSelected;

		// TODO: only show alert when this is an unknown mode
		BWindow* window = new AlertWindow(this);
		window->Show();
	} else {
		char message[256];
		snprintf(message, sizeof(message),
			B_TRANSLATE("The screen mode could not be set:\n\t%s\n"),
			screen_errors(status));
		BAlert* alert = new BAlert(B_TRANSLATE("Warning"), message,
			B_TRANSLATE("OK"), NULL, NULL,
			B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go();
	}
}
Beispiel #3
0
// this method assumes that you already reverted to the correct number of workspaces
status_t
ScreenMode::Revert()
{
	if (!fUpdatedModes)
		return B_ERROR;

	status_t result = B_OK;
	screen_mode current;
	for (int32 workspace = 0; workspace < count_workspaces(); workspace++) {
		if (Get(current, workspace) == B_OK && fOriginal[workspace] == current)
			continue;

		BScreen screen(fWindow);

		result = screen.SetMode(workspace, &fOriginalDisplayMode[workspace], true);
		if (result != B_OK)
			break;
	}
	
	return result;
}
Beispiel #4
0
status_t
BackgroundThemesAddon::MakeTheme(BMessage &theme, uint32 flags)
{
	BMessage backgrounds;
	status_t err = B_OK;
	BPath pDesktop;
	struct attr_info ai;
	char *pAttr;
	BScreen bs;
	rgb_color last_color = {0, 0, 0, 254};
	rgb_color col;
	int last_change = 0;
	int i;
	
	(void)flags;
	err = MyMessage(theme, backgrounds);
	if (err)
		backgrounds.MakeEmpty();
	
	if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK)
		return EINVAL;
	BNode nDesktop(pDesktop.Path());
	if (nDesktop.InitCheck() < B_OK)
		return nDesktop.InitCheck();
	if (nDesktop.GetAttrInfo(B_BACKGROUND_INFO, &ai) < B_OK)
		return EIO;
	pAttr = new char[ai.size];
	if (pAttr == NULL)
		return ENOMEM;
	err = nDesktop.ReadAttr(B_BACKGROUND_INFO, ai.type, 0LL, pAttr, ai.size);
	if (err < B_OK)
		goto getout;
	err = backgrounds.Unflatten(pAttr);
	if (err < B_OK)
		goto getout;

	// make sure other colors are removed
	backgrounds.RemoveName(B__DESKTOP_COLOR);

	// get desktop color... XXX: move it in ui_settings ?
	// should work as the rest of the fields (grouping)
	for (i = 0; i < count_workspaces(); i++) {
		col = bs.DesktopColor(i);
		if (memcmp(&last_color, &col, sizeof(rgb_color))) {
			last_change = i;
			last_color = col;
		}
	}
	//printf("ws col cnt %d\n", last_change);
	for (i = 0; i <= last_change; i++) {
		col = bs.DesktopColor(i);
		AddRGBColor(backgrounds, B__DESKTOP_COLOR, col);
		//backgrounds->AddData(B__DESKTOP_COLOR, (type_code)'RGBC', &col, 4);
	}

	err = SetMyMessage(theme, backgrounds);
	return err;

getout:
	delete [] pAttr;
	return err;
}
Beispiel #5
0
status_t
BackgroundThemesAddon::ApplyTheme(BMessage &theme, uint32 flags)
{
	BMessage backgrounds;
	status_t err = B_OK;
	BPath pDesktop;
	ssize_t flatSize;
	char *pAttr;

	if (!(flags & UI_THEME_SETTINGS_SET_ALL) || !(AddonFlags() & Z_THEME_ADDON_DO_SET_ALL))
		return B_OK;

	err = MyMessage(theme, backgrounds);
	if (err)
		return err;

	// set desktop colors
	BScreen bs;
	rgb_color col;
	//const rgb_color *c;
	col = bs.DesktopColor(0); // by
	// should work as the rest of the fields (grouping)
	for (int i = 0; i < count_workspaces(); i++) {
		//ssize_t sz = 4;
		if (FindRGBColor(backgrounds, B__DESKTOP_COLOR, i, &col) != B_OK && i == 0)
		//if (backgrounds.FindData(B__DESKTOP_COLOR, (type_code)'RGBC', i, (const void **)&c, &sz) != B_OK && i == 0)
			break; // if no color at all, don't set them
		bs.SetDesktopColor(col, i, true);
	}
	// make sure we don't leave our garbage in the message
	// as it would offset the next call by adding rgb_colors on existing ones
	backgrounds.RemoveName(B__DESKTOP_COLOR);

	BMessenger tracker("application/x-vnd.Be-TRAK");
	BMessage m(B_RESTORE_BACKGROUND_IMAGE);

	if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK)
		return EINVAL;
	BNode nDesktop(pDesktop.Path());
	if (nDesktop.InitCheck() < B_OK)
		return nDesktop.InitCheck();
	flatSize = backgrounds.FlattenedSize();
	pAttr = new char[flatSize];
	if (pAttr == NULL)
		return ENOMEM;
	err = backgrounds.Flatten(pAttr, flatSize);
	if (err < B_OK)
		goto getout;
	err = nDesktop.WriteAttr(B_BACKGROUND_INFO, B_MESSAGE_TYPE, 0LL, pAttr, flatSize);
	if (err < B_OK)
		goto getout;

	//m.AddSpecifier("Window", "Desktop");
	tracker.SendMessage(&m);

	return B_OK;

getout:
	delete [] pAttr;
	return err;
}