* Modified PtrScr key behaviour:

- No modifiers: take a screenshot with zero delay and launch the GUI
  - Shift-PrtScr: Silent screenshot using the saved GUI settings
  - Ctrl-PrtScr: Take a screenshot using the saved GUI settings and copy the
    screenshot to the system clipboard
* A few locale related changes (I am not sure how this works when a class is
  shared between two applications, I hope I got everything right)



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37252 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Wim van der Meer 2010-06-25 13:12:15 +00:00
parent 36c80d7002
commit 0c9f5a026f
9 changed files with 139 additions and 67 deletions

View File

@ -24,3 +24,9 @@ Application screenshot :
: be locale translation $(TARGET_LIBSUPC++)
: Screenshot.rdef
;
DoCatalogs screenshot :
x-vnd.haiku-screenshot-cli
:
Utility.cpp
;

View File

@ -19,6 +19,7 @@
#include <AppDefs.h>
#include <Bitmap.h>
#include <Catalog.h>
#include <Locale.h>
#include <Roster.h>
#include <Screen.h>
@ -29,6 +30,10 @@
#include "Utility.h"
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Screenshot"
Screenshot::Screenshot()
:
BApplication("application/x-vnd.haiku-screenshot-cli"),
@ -56,7 +61,6 @@ Screenshot::ArgvReceived(int32 argc, char** argv)
bool saveScreenshotSilent = false;
bool copyToClipboard = false;
uint32 imageFileType = B_PNG_FORMAT;
for (int32 i = 0; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
_ShowHelp();
@ -98,8 +102,7 @@ Screenshot::ArgvReceived(int32 argc, char** argv)
outputFilename = argv[i];
}
if (argc > 1)
_New(delay);
_New(delay);
if (copyToClipboard || saveScreenshotSilent) {
fLaunchGui = false;
@ -125,35 +128,32 @@ void
Screenshot::ReadyToRun()
{
if (fLaunchGui) {
// Launch the GUI application
if (fUtility->wholeScreen == NULL) {
// No command line parameters were given
be_roster->Launch("application/x-vnd.haiku-screenshot");
} else {
// Send the utility data and the command line settings to the GUI
BMessage message;
message.what = SS_UTILITY_DATA;
// Get a screenshot if we don't have one
if (fUtility->wholeScreen == NULL)
_New(0);
BMessage* bitmap = new BMessage();
fUtility->wholeScreen->Archive(bitmap);
message.AddMessage("wholeScreen", bitmap);
// Send the screenshot data to the GUI
BMessage message;
message.what = SS_UTILITY_DATA;
bitmap = new BMessage();
fUtility->cursorBitmap->Archive(bitmap);
message.AddMessage("cursorBitmap", bitmap);
BMessage* bitmap = new BMessage();
fUtility->wholeScreen->Archive(bitmap);
message.AddMessage("wholeScreen", bitmap);
bitmap = new BMessage();
fUtility->cursorAreaBitmap->Archive(bitmap);
message.AddMessage("cursorAreaBitmap", bitmap);
bitmap = new BMessage();
fUtility->cursorBitmap->Archive(bitmap);
message.AddMessage("cursorBitmap", bitmap);
message.AddPoint("cursorPosition", fUtility->cursorPosition);
message.AddRect("activeWindowFrame", fUtility->activeWindowFrame);
message.AddRect("tabFrame", fUtility->tabFrame);
message.AddFloat("borderSize", fUtility->borderSize);
bitmap = new BMessage();
fUtility->cursorAreaBitmap->Archive(bitmap);
message.AddMessage("cursorAreaBitmap", bitmap);
be_roster->Launch("application/x-vnd.haiku-screenshot",
&message);
}
message.AddPoint("cursorPosition", fUtility->cursorPosition);
message.AddRect("activeWindowFrame", fUtility->activeWindowFrame);
message.AddRect("tabFrame", fUtility->tabFrame);
message.AddFloat("borderSize", fUtility->borderSize);
be_roster->Launch("application/x-vnd.haiku-screenshot", &message);
}
be_app->PostMessage(B_QUIT_REQUESTED);

View File

@ -27,7 +27,7 @@ private:
void _New(bigtime_t delay);
status_t _GetActiveWindowFrame();
int32 _GetImageType(const char* name) const;
Utility* fUtility;
BCatalog fCatalog;

View File

@ -12,6 +12,7 @@
#include <stdlib.h>
#include <Bitmap.h>
#include <Catalog.h>
#include <Locale.h>
#include <Roster.h>
@ -22,7 +23,9 @@
ScreenshotApp::ScreenshotApp()
:
BApplication("application/x-vnd.haiku-screenshot"),
fUtility(new Utility)
fUtility(new Utility),
fSilent(false),
fClipboard(false)
{
be_locale->GetAppCatalog(&fCatalog);
}
@ -91,10 +94,24 @@ ScreenshotApp::MessageReceived(BMessage* message)
}
void
ScreenshotApp::ArgvReceived(int32 argc, char** argv)
{
for (int32 i = 0; i < argc; i++) {
if (strcmp(argv[i], "-s") == 0
|| strcmp(argv[i], "--silent") == 0)
fSilent = true;
else if (strcmp(argv[i], "-c") == 0
|| strcmp(argv[i], "--clipboard") == 0)
fClipboard = true;
}
}
void
ScreenshotApp::ReadyToRun()
{
new ScreenshotWindow(*fUtility);
new ScreenshotWindow(*fUtility, fSilent, fClipboard);
}

View File

@ -22,11 +22,14 @@ public:
~ScreenshotApp();
void MessageReceived(BMessage* message);
void ArgvReceived(int32 argc, char** argv);
void ReadyToRun();
private:
BCatalog fCatalog;
Utility* fUtility;
bool fSilent;
bool fClipboard;
};

View File

@ -27,6 +27,7 @@
#include <FindDirectory.h>
#include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h>
#include <Locale.h>
#include <Menu.h>
#include <MenuField.h>
#include <MenuItem.h>
@ -71,7 +72,8 @@ public:
#define B_TRANSLATE_CONTEXT "ScreenshotWindow"
ScreenshotWindow::ScreenshotWindow(const Utility& utility)
ScreenshotWindow::ScreenshotWindow(const Utility& utility, bool silent,
bool clipboard)
:
BWindow(BRect(0, 0, 200.0, 100.0), B_TRANSLATE("Screenshot"),
B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AVOID_FRONT
@ -90,17 +92,22 @@ ScreenshotWindow::ScreenshotWindow(const Utility& utility)
fExtension(""),
fImageFileType(B_PNG_FORMAT)
{
// Check if fUtility contains valid data
if (fUtility.wholeScreen == NULL) {
// New screenshot using zero delay
_NewScreenshot();
return;
}
// _ReadSettings() needs a valid fOutputPathMenu
fOutputPathMenu = new BMenu(B_TRANSLATE("Please select"));
_ReadSettings();
// _NewScreenshot() needs a valid fNameControl
BString name(B_TRANSLATE(fUtility.sDefaultFileNameBase));
name << 1;
name = _FindValidFileName(name.String());
fNameControl = new BTextControl("", B_TRANSLATE("Name:"), name, NULL);
// Check if fUtility contains valid data
if (fUtility.wholeScreen == NULL) {
_NewScreenshot(silent, clipboard);
return;
}
fScreenshot = fUtility.MakeScreenshot(fIncludeCursor, fGrabActiveWindow,
fIncludeBorder);
@ -130,11 +137,6 @@ ScreenshotWindow::ScreenshotWindow(const Utility& utility)
BStringView* seconds = new BStringView("", B_TRANSLATE("seconds"));
seconds->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
BString name(fUtility.sDefaultFileNameBase);
name << 1;
name = _FindValidFileName(name.String());
fNameControl = new BTextControl("", B_TRANSLATE("Name:"), name, NULL);
BMenuField* menuField2 = new BMenuField(B_TRANSLATE("Save in:"),
fOutputPathMenu);
@ -318,21 +320,49 @@ ScreenshotWindow::Quit()
void
ScreenshotWindow::_NewScreenshot()
ScreenshotWindow::_NewScreenshot(bool silent, bool clipboard)
{
BMessage message(B_ARGV_RECEIVED);
int32 argc = 3;
char* argv[3];
argv[0] = "Screenshot";
argv[1] = "--delay";
BString delay;
delay << fDelay / 1000000;
int32 charCount = delay.Length();
argv[2] = (char*)malloc(charCount + 1);
delay.CopyInto(argv[2], 0, charCount);
argv[2][charCount] = '\0';
message.AddString("argv", "screenshot");
message.AddString("argv", "--delay");
message.AddString("argv", delay);
if (silent || clipboard) {
if (silent) {
argc++;
message.AddString("argv", "--silent");
}
if (clipboard) {
argc++;
message.AddString("argv", "--clipboard");
}
if (fIncludeBorder) {
argc++;
message.AddString("argv", "--border");
}
if (fIncludeCursor) {
argc++;
message.AddString("argv", "--mouse-pointer");
}
if (fGrabActiveWindow) {
argc++;
message.AddString("argv", "--window");
}
if (fLastSelectedPath) {
BPath path(_GetDirectory());
if (path != NULL) {
path.Append(fNameControl->Text());
argc++;
message.AddString("argv", path.Path());
}
}
}
message.AddInt32("argc", argc);
be_roster->Launch("application/x-vnd.haiku-screenshot-cli", argc, argv);
be_roster->Launch("application/x-vnd.haiku-screenshot-cli", &message);
be_app->PostMessage(B_QUIT_REQUESTED);
}
@ -538,7 +568,7 @@ ScreenshotWindow::_FindValidFileName(const char* name)
if (!BEntry(outputPath.Path()).Exists())
return fileName;
if (baseName.FindFirst(fUtility.sDefaultFileNameBase) == 0)
if (baseName.FindFirst(B_TRANSLATE(fUtility.sDefaultFileNameBase)) == 0)
baseName.SetTo(fUtility.sDefaultFileNameBase);
BEntry entry;

View File

@ -32,14 +32,16 @@ class Utility;
class ScreenshotWindow : public BWindow {
public:
ScreenshotWindow(const Utility& utility);
ScreenshotWindow(const Utility& utility,
bool silent, bool clipboard);
~ScreenshotWindow();
void MessageReceived(BMessage* message);
void Quit();
private:
void _NewScreenshot();
void _NewScreenshot(bool silent = false,
bool clipboard = false);
void _UpdatePreviewPanel();
void _DisallowChar(BTextView* textView);
void _SetupOutputPathMenu(const BMessage& settings);

View File

@ -20,6 +20,7 @@
#include <Entry.h>
#include <File.h>
#include <FindDirectory.h>
#include <Locale.h>
#include <Looper.h>
#include <MimeType.h>
#include <NodeInfo.h>
@ -96,7 +97,7 @@ Utility::Save(BBitmap** screenshot, const char* fileName, uint32 imageType)
BString extension = GetFileNameExtension(imageType);
do {
fileNameString.SetTo(homePath.Path());
fileNameString << "/" << sDefaultFileNameBase << index++
fileNameString << "/" << B_TRANSLATE(sDefaultFileNameBase) << index++
<< extension;
entry.SetTo(fileNameString.String());
} while (entry.Exists());
@ -204,7 +205,7 @@ Utility::GetFileNameExtension(uint32 imageType) const
const char*
Utility::_GetMimeString(uint32 imageType) const
{
char dummy[] = "";
const char *dummy = "";
translator_id* translators = NULL;
int32 numTranslators = 0;
BTranslatorRoster* roster = BTranslatorRoster::Default();

View File

@ -3608,17 +3608,30 @@ BWindow::_HandleKeyDown(BMessage* event)
return true;
}
// PrtScr key takes a screenshot
if (key == B_FUNCTION_KEY && rawKey == B_PRINT_KEY) {
BMessage message(B_REFS_RECEIVED);
message.AddBool("silent", true);
// With no modifier keys the best way to get a screenshot is by
// calling the screenshot CLI
if (modifiers == 0) {
be_roster->Launch("application/x-vnd.haiku-screenshot-cli");
return true;
}
if ((modifiers & B_CONTROL_KEY) != 0)
message.AddBool("window", true);
if ((modifiers & B_SHIFT_KEY) != 0 || (modifiers & B_OPTION_KEY) != 0)
message.ReplaceBool("silent", false);
be_roster->Launch("application/x-vnd.haiku-screenshot-cli", &message);
// Prepare a message based on the modifier keys pressed and launch the
// screenshot GUI
BMessage message(B_ARGV_RECEIVED);
int32 argc = 1;
message.AddString("argv", "Screenshot");
if ((modifiers & B_CONTROL_KEY) != 0) {
argc++;
message.AddString("argv", "--clipboard");
}
if ((modifiers & B_SHIFT_KEY) != 0) {
argc++;
message.AddString("argv", "--silent");
}
message.AddInt32("argc", argc);
be_roster->Launch("application/x-vnd.haiku-screenshot", &message);
return true;
}