* 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
+6
View File
@@ -24,3 +24,9 @@ Application screenshot :
: be locale translation $(TARGET_LIBSUPC++) : be locale translation $(TARGET_LIBSUPC++)
: Screenshot.rdef : Screenshot.rdef
; ;
DoCatalogs screenshot :
x-vnd.haiku-screenshot-cli
:
Utility.cpp
;
+27 -27
View File
@@ -19,6 +19,7 @@
#include <AppDefs.h> #include <AppDefs.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
@@ -29,6 +30,10 @@
#include "Utility.h" #include "Utility.h"
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Screenshot"
Screenshot::Screenshot() Screenshot::Screenshot()
: :
BApplication("application/x-vnd.haiku-screenshot-cli"), BApplication("application/x-vnd.haiku-screenshot-cli"),
@@ -56,7 +61,6 @@ Screenshot::ArgvReceived(int32 argc, char** argv)
bool saveScreenshotSilent = false; bool saveScreenshotSilent = false;
bool copyToClipboard = false; bool copyToClipboard = false;
uint32 imageFileType = B_PNG_FORMAT; uint32 imageFileType = B_PNG_FORMAT;
for (int32 i = 0; i < argc; i++) { for (int32 i = 0; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
_ShowHelp(); _ShowHelp();
@@ -98,8 +102,7 @@ Screenshot::ArgvReceived(int32 argc, char** argv)
outputFilename = argv[i]; outputFilename = argv[i];
} }
if (argc > 1) _New(delay);
_New(delay);
if (copyToClipboard || saveScreenshotSilent) { if (copyToClipboard || saveScreenshotSilent) {
fLaunchGui = false; fLaunchGui = false;
@@ -125,35 +128,32 @@ void
Screenshot::ReadyToRun() Screenshot::ReadyToRun()
{ {
if (fLaunchGui) { if (fLaunchGui) {
// Launch the GUI application // Get a screenshot if we don't have one
if (fUtility->wholeScreen == NULL) { if (fUtility->wholeScreen == NULL)
// No command line parameters were given _New(0);
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;
BMessage* bitmap = new BMessage(); // Send the screenshot data to the GUI
fUtility->wholeScreen->Archive(bitmap); BMessage message;
message.AddMessage("wholeScreen", bitmap); message.what = SS_UTILITY_DATA;
bitmap = new BMessage(); BMessage* bitmap = new BMessage();
fUtility->cursorBitmap->Archive(bitmap); fUtility->wholeScreen->Archive(bitmap);
message.AddMessage("cursorBitmap", bitmap); message.AddMessage("wholeScreen", bitmap);
bitmap = new BMessage(); bitmap = new BMessage();
fUtility->cursorAreaBitmap->Archive(bitmap); fUtility->cursorBitmap->Archive(bitmap);
message.AddMessage("cursorAreaBitmap", bitmap); message.AddMessage("cursorBitmap", bitmap);
message.AddPoint("cursorPosition", fUtility->cursorPosition); bitmap = new BMessage();
message.AddRect("activeWindowFrame", fUtility->activeWindowFrame); fUtility->cursorAreaBitmap->Archive(bitmap);
message.AddRect("tabFrame", fUtility->tabFrame); message.AddMessage("cursorAreaBitmap", bitmap);
message.AddFloat("borderSize", fUtility->borderSize);
be_roster->Launch("application/x-vnd.haiku-screenshot", message.AddPoint("cursorPosition", fUtility->cursorPosition);
&message); 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); be_app->PostMessage(B_QUIT_REQUESTED);
+19 -2
View File
@@ -12,6 +12,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include <Roster.h> #include <Roster.h>
@@ -22,7 +23,9 @@
ScreenshotApp::ScreenshotApp() ScreenshotApp::ScreenshotApp()
: :
BApplication("application/x-vnd.haiku-screenshot"), BApplication("application/x-vnd.haiku-screenshot"),
fUtility(new Utility) fUtility(new Utility),
fSilent(false),
fClipboard(false)
{ {
be_locale->GetAppCatalog(&fCatalog); 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 void
ScreenshotApp::ReadyToRun() ScreenshotApp::ReadyToRun()
{ {
new ScreenshotWindow(*fUtility); new ScreenshotWindow(*fUtility, fSilent, fClipboard);
} }
+3
View File
@@ -22,11 +22,14 @@ public:
~ScreenshotApp(); ~ScreenshotApp();
void MessageReceived(BMessage* message); void MessageReceived(BMessage* message);
void ArgvReceived(int32 argc, char** argv);
void ReadyToRun(); void ReadyToRun();
private: private:
BCatalog fCatalog; BCatalog fCatalog;
Utility* fUtility; Utility* fUtility;
bool fSilent;
bool fClipboard;
}; };
+54 -24
View File
@@ -27,6 +27,7 @@
#include <FindDirectory.h> #include <FindDirectory.h>
#include <GridLayoutBuilder.h> #include <GridLayoutBuilder.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <Locale.h>
#include <Menu.h> #include <Menu.h>
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
@@ -71,7 +72,8 @@ public:
#define B_TRANSLATE_CONTEXT "ScreenshotWindow" #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"), BWindow(BRect(0, 0, 200.0, 100.0), B_TRANSLATE("Screenshot"),
B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AVOID_FRONT B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AVOID_FRONT
@@ -90,17 +92,22 @@ ScreenshotWindow::ScreenshotWindow(const Utility& utility)
fExtension(""), fExtension(""),
fImageFileType(B_PNG_FORMAT) 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 // _ReadSettings() needs a valid fOutputPathMenu
fOutputPathMenu = new BMenu(B_TRANSLATE("Please select")); fOutputPathMenu = new BMenu(B_TRANSLATE("Please select"));
_ReadSettings(); _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, fScreenshot = fUtility.MakeScreenshot(fIncludeCursor, fGrabActiveWindow,
fIncludeBorder); fIncludeBorder);
@@ -130,11 +137,6 @@ ScreenshotWindow::ScreenshotWindow(const Utility& utility)
BStringView* seconds = new BStringView("", B_TRANSLATE("seconds")); BStringView* seconds = new BStringView("", B_TRANSLATE("seconds"));
seconds->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); 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:"), BMenuField* menuField2 = new BMenuField(B_TRANSLATE("Save in:"),
fOutputPathMenu); fOutputPathMenu);
@@ -318,21 +320,49 @@ ScreenshotWindow::Quit()
void void
ScreenshotWindow::_NewScreenshot() ScreenshotWindow::_NewScreenshot(bool silent, bool clipboard)
{ {
BMessage message(B_ARGV_RECEIVED);
int32 argc = 3; int32 argc = 3;
char* argv[3];
argv[0] = "Screenshot";
argv[1] = "--delay";
BString delay; BString delay;
delay << fDelay / 1000000; delay << fDelay / 1000000;
int32 charCount = delay.Length(); message.AddString("argv", "screenshot");
argv[2] = (char*)malloc(charCount + 1); message.AddString("argv", "--delay");
delay.CopyInto(argv[2], 0, charCount); message.AddString("argv", delay);
argv[2][charCount] = '\0';
be_roster->Launch("application/x-vnd.haiku-screenshot-cli", argc, argv); 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", &message);
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
} }
@@ -538,7 +568,7 @@ ScreenshotWindow::_FindValidFileName(const char* name)
if (!BEntry(outputPath.Path()).Exists()) if (!BEntry(outputPath.Path()).Exists())
return fileName; return fileName;
if (baseName.FindFirst(fUtility.sDefaultFileNameBase) == 0) if (baseName.FindFirst(B_TRANSLATE(fUtility.sDefaultFileNameBase)) == 0)
baseName.SetTo(fUtility.sDefaultFileNameBase); baseName.SetTo(fUtility.sDefaultFileNameBase);
BEntry entry; BEntry entry;
+4 -2
View File
@@ -32,14 +32,16 @@ class Utility;
class ScreenshotWindow : public BWindow { class ScreenshotWindow : public BWindow {
public: public:
ScreenshotWindow(const Utility& utility); ScreenshotWindow(const Utility& utility,
bool silent, bool clipboard);
~ScreenshotWindow(); ~ScreenshotWindow();
void MessageReceived(BMessage* message); void MessageReceived(BMessage* message);
void Quit(); void Quit();
private: private:
void _NewScreenshot(); void _NewScreenshot(bool silent = false,
bool clipboard = false);
void _UpdatePreviewPanel(); void _UpdatePreviewPanel();
void _DisallowChar(BTextView* textView); void _DisallowChar(BTextView* textView);
void _SetupOutputPathMenu(const BMessage& settings); void _SetupOutputPathMenu(const BMessage& settings);
+3 -2
View File
@@ -20,6 +20,7 @@
#include <Entry.h> #include <Entry.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Locale.h>
#include <Looper.h> #include <Looper.h>
#include <MimeType.h> #include <MimeType.h>
#include <NodeInfo.h> #include <NodeInfo.h>
@@ -96,7 +97,7 @@ Utility::Save(BBitmap** screenshot, const char* fileName, uint32 imageType)
BString extension = GetFileNameExtension(imageType); BString extension = GetFileNameExtension(imageType);
do { do {
fileNameString.SetTo(homePath.Path()); fileNameString.SetTo(homePath.Path());
fileNameString << "/" << sDefaultFileNameBase << index++ fileNameString << "/" << B_TRANSLATE(sDefaultFileNameBase) << index++
<< extension; << extension;
entry.SetTo(fileNameString.String()); entry.SetTo(fileNameString.String());
} while (entry.Exists()); } while (entry.Exists());
@@ -204,7 +205,7 @@ Utility::GetFileNameExtension(uint32 imageType) const
const char* const char*
Utility::_GetMimeString(uint32 imageType) const Utility::_GetMimeString(uint32 imageType) const
{ {
char dummy[] = ""; const char *dummy = "";
translator_id* translators = NULL; translator_id* translators = NULL;
int32 numTranslators = 0; int32 numTranslators = 0;
BTranslatorRoster* roster = BTranslatorRoster::Default(); BTranslatorRoster* roster = BTranslatorRoster::Default();
+22 -9
View File
@@ -3608,17 +3608,30 @@ BWindow::_HandleKeyDown(BMessage* event)
return true; return true;
} }
// PrtScr key takes a screenshot
if (key == B_FUNCTION_KEY && rawKey == B_PRINT_KEY) { if (key == B_FUNCTION_KEY && rawKey == B_PRINT_KEY) {
BMessage message(B_REFS_RECEIVED); // With no modifier keys the best way to get a screenshot is by
message.AddBool("silent", true); // calling the screenshot CLI
if (modifiers == 0) {
be_roster->Launch("application/x-vnd.haiku-screenshot-cli");
return true;
}
if ((modifiers & B_CONTROL_KEY) != 0) // Prepare a message based on the modifier keys pressed and launch the
message.AddBool("window", true); // screenshot GUI
BMessage message(B_ARGV_RECEIVED);
if ((modifiers & B_SHIFT_KEY) != 0 || (modifiers & B_OPTION_KEY) != 0) int32 argc = 1;
message.ReplaceBool("silent", false); message.AddString("argv", "Screenshot");
if ((modifiers & B_CONTROL_KEY) != 0) {
be_roster->Launch("application/x-vnd.haiku-screenshot-cli", &message); 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; return true;
} }