Ticket #3209: TerminalPosition.patch
File TerminalPosition.patch, 9.0 KB (added by , 15 years ago) |
---|
-
src/apps/terminal/TermWindow.cpp
1 1 /* 2 * Copyright 2007 Haiku, Inc.2 * Copyright 2007-2009 Haiku, Inc. 3 3 * Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net> 4 4 * Copyright (c) 2003-2004 Kian Duffy <myob@users.sourceforge.net> 5 5 * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. … … 130 130 }; 131 131 132 132 133 TermWindow::TermWindow(BRect frame, const char* title, Arguments *args)133 TermWindow::TermWindow(BRect frame, const char* title, uint32 workspaces, Arguments *args) 134 134 : 135 BWindow(frame, title, B_DOCUMENT_WINDOW, 136 B_CURRENT_WORKSPACE | B_QUIT_ON_WINDOW_CLOSE), 135 BWindow(frame, title, B_DOCUMENT_WINDOW, B_QUIT_ON_WINDOW_CLOSE, workspaces), 137 136 fInitialTitle(title), 138 137 fTabView(NULL), 139 138 fMenubar(NULL), … … 168 167 fFindPanel->Quit(); 169 168 fFindPanel = NULL; 170 169 } 171 170 172 171 PrefHandler::DeleteDefault(); 173 172 174 173 for (int32 i = 0; Session* session = (Session*)fSessions.ItemAt(i); i++) … … 615 614 } 616 615 617 616 617 bool 618 TermWindow::QuitRequested() 619 { 620 BMessage position = BMessage(MSG_SAVE_WINDOW_POSITION); 621 position.AddRect("rect", Frame()); 622 position.AddInt32("workspaces", Workspaces()); 623 be_app->PostMessage(&position); 624 625 return true; 626 } 627 628 618 629 void 619 630 TermWindow::_SetTermColors(TermViewContainerView *containerView) 620 631 { -
src/apps/terminal/TermApp.h
1 1 /* 2 * Copyright 2001-200 8, Haiku.2 * Copyright 2001-2009, Haiku. 3 3 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net> 4 4 * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. 5 5 * … … 33 33 34 34 35 35 #include <Application.h> 36 #include <File.h> 36 37 #include <String.h> 37 38 38 39 class Arguments; … … 52 53 void ArgvReceived(int32 argc, char** argv); 53 54 54 55 private: 55 status_t _MakeTermWindow(BRect& frame); 56 status_t _GetWindowPositionsFile(BFile* file, uint32 openMode); 57 status_t _LoadWindowPosition(BRect* frame, uint32* workspaces); 58 status_t _SaveWindowPosition(BMessage* message); 59 status_t _MakeTermWindow(BRect& frame, uint32 workspaces); 56 60 void _SwitchTerm(); 57 61 void _ActivateTermWindow(team_id id); 58 62 bool _IsSwitchTarget(team_id id); … … 75 79 76 80 BWindow* fTermWindow; 77 81 BRect fTermFrame; 82 uint32 fTermWorkspaces; 78 83 Arguments *fArgs; 79 84 }; 80 85 -
src/apps/terminal/TermWindow.h
1 1 /* 2 * Copyright 2001-200 7, Haiku.2 * Copyright 2001-2009, Haiku. 3 3 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net> 4 4 * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. 5 5 * … … 48 48 49 49 class TermWindow : public BWindow { 50 50 public: 51 TermWindow(BRect frame, const char* title, Arguments *args);51 TermWindow(BRect frame, const char* title, uint32 workspaces, Arguments *args); 52 52 virtual ~TermWindow(); 53 53 54 54 void SetSessionWindowTitle(TermView* termView, … … 59 59 virtual void MessageReceived(BMessage *message); 60 60 virtual void WindowActivated(bool); 61 61 virtual void MenusBeginning(); 62 62 virtual bool QuitRequested(); 63 63 64 private: 64 65 struct Session; 65 66 class TabView; -
src/apps/terminal/TermApp.cpp
1 1 /* 2 * Copyright 2001-200 8, Haiku.2 * Copyright 2001-2009, Haiku. 3 3 * Copyright (c) 2003-2004 Kian Duffy <myob@users.sourceforge.net> 4 4 * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. 5 5 * … … 17 17 18 18 #include <Alert.h> 19 19 #include <Clipboard.h> 20 #include <FindDirectory.h> 21 #include <InterfaceDefs.h> 20 22 #include <NodeInfo.h> 21 23 #include <Path.h> 22 24 #include <Roster.h> … … 45 47 fStartFullscreen(false), 46 48 fWindowNumber(-1), 47 49 fTermWindow(NULL), 50 fTermWorkspaces(B_CURRENT_WORKSPACE), 48 51 fArgs(NULL) 49 52 { 50 53 fArgs = new Arguments(); … … 55 58 if (fWindowNumber > 0) 56 59 fWindowTitle << " " << fWindowNumber; 57 60 58 int i = fWindowNumber / 16; 59 int j = fWindowNumber % 16; 60 int k = (j * 16) + (i * 64) + 50; 61 int l = (j * 16) + 50; 61 if (_LoadWindowPosition(&fTermFrame, &fTermWorkspaces) != B_OK) { 62 int i = fWindowNumber / 16; 63 int j = fWindowNumber % 16; 64 int k = (j * 16) + (i * 64) + 50; 65 int l = (j * 16) + 50; 62 66 63 fTermFrame.Set(k, l, k + 50, k + 50); 67 fTermFrame.Set(k, l, k + 50, k + 50); 68 } 64 69 } 65 70 66 71 … … 98 103 // init the mouse copy'n'paste clipboard 99 104 gMouseClipboard = new BClipboard(MOUSE_CLIPBOARD_NAME, true); 100 105 101 status_t status = _MakeTermWindow(fTermFrame );106 status_t status = _MakeTermWindow(fTermFrame, fTermWorkspaces); 102 107 103 108 // failed spawn, print stdout and open alert panel 104 109 // TODO: This alert does never show up. … … 119 124 void 120 125 TermApp::Quit() 121 126 { 127 fTermWindow->PostMessage(B_QUIT_REQUESTED); 128 122 129 if (!sUsageRequested) 123 130 _UnregisterTerminal(); 124 131 … … 168 175 break; 169 176 } 170 177 178 case MSG_SAVE_WINDOW_POSITION: 179 _SaveWindowPosition(msg); 180 break; 181 171 182 case MSG_CHECK_CHILDREN: 172 183 _HandleChildCleanup(); 173 184 break; … … 236 247 237 248 238 249 status_t 239 TermApp::_ MakeTermWindow(BRect &frame)250 TermApp::_GetWindowPositionsFile(BFile* file, uint32 openMode) 240 251 { 252 BPath path; 253 status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); 254 if (status != B_OK) 255 return status; 256 257 status = path.Append("Terminal_windows"); 258 if (status != B_OK) 259 return status; 260 261 return file->SetTo(path.Path(), openMode); 262 } 263 264 status_t 265 TermApp::_LoadWindowPosition(BRect* frame, uint32* workspaces) 266 { 267 BClipboard clipboard(TERM_SIGNATURE); 268 if (!clipboard.Lock()) 269 return B_ERROR; 270 271 status_t status = B_ERROR; 272 BMessage position = BMessage(); 273 274 while (true) { 275 BFile file; 276 status = _GetWindowPositionsFile (&file, B_READ_ONLY); 277 if (status != B_OK) 278 break;; 279 280 status = position.Unflatten(&file); 281 282 file.Unset(); 283 break; 284 } 285 286 clipboard.Unlock(); 287 288 if (status != B_OK) 289 return status; 290 291 status = position.FindRect((BString("rect_") << fWindowNumber).String(), frame); 292 if (status != B_OK) 293 return status; 294 295 int32 _workspaces; 296 status = position.FindInt32((BString("workspaces_") << fWindowNumber).String(), &_workspaces); 297 if (status != B_OK) 298 return status; 299 if (modifiers() & B_OPTION_KEY) 300 *workspaces = _workspaces; 301 302 return B_OK; 303 } 304 305 306 status_t 307 TermApp::_SaveWindowPosition(BMessage* position) 308 { 309 BRect frame; 310 status_t status = position->FindRect("rect", &frame); 311 if (status != B_OK) 312 return status; 313 314 int32 workspaces; 315 status = position->FindInt32("workspaces", &workspaces); 316 if (status != B_OK) 317 return status; 318 319 status = position->MakeEmpty(); 320 if (status != B_OK) 321 return status; 322 323 BClipboard clipboard(TERM_SIGNATURE); 324 if (!clipboard.Lock()) 325 return B_ERROR; 326 327 while (true) { 328 BFile file; 329 status = _GetWindowPositionsFile (&file, B_READ_ONLY); 330 if (status == B_OK) { 331 status = position->Unflatten(&file); 332 if (status != B_OK) 333 break;; 334 } 335 336 status = position->ReplaceRect((BString("rect_") << fWindowNumber).String(), frame); 337 if (status != B_OK) { 338 status = position->AddRect((BString("rect_") << fWindowNumber).String(), frame); 339 if (status != B_OK) 340 break; 341 } 342 343 status = position->ReplaceInt32((BString("workspaces_") << fWindowNumber).String(), workspaces); 344 if (status != B_OK) { 345 status = position->AddInt32((BString("workspaces_") << fWindowNumber).String(), workspaces); 346 if (status != B_OK) 347 break; 348 } 349 350 file.Unset(); 351 status = _GetWindowPositionsFile (&file, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); 352 if (status != B_OK) 353 break; 354 355 status = position->Flatten(&file); 356 break; 357 } 358 359 clipboard.Unlock(); 360 361 return status; 362 } 363 364 365 status_t 366 TermApp::_MakeTermWindow(BRect &frame, uint32 workspaces) 367 { 241 368 try { 242 fTermWindow = new TermWindow(frame, fWindowTitle.String(), fArgs);369 fTermWindow = new TermWindow(frame, fWindowTitle.String(), workspaces, fArgs); 243 370 } catch (int error) { 244 371 return (status_t)error; 245 372 } catch (...) { -
src/apps/terminal/TermConst.h
1 1 /* 2 * Copyright 2001-200 8, Haiku.2 * Copyright 2001-2009, Haiku. 3 3 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net> 4 4 * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. 5 5 * … … 92 92 const uint32 MSG_SET_TERMNAL_TITLE = 'sett'; 93 93 const uint32 MSG_QUIT_TERMNAL = 'qutt'; 94 94 95 const uint32 MSG_SAVE_WINDOW_POSITION = 'swps'; 96 95 97 // Preference Read/Write Keys 96 98 const char* const PREF_HALF_FONT_FAMILY = "Half Font Family"; 97 99 const char* const PREF_HALF_FONT_STYLE = "Half Font Style";