Ticket #3209: TerminalPosition.patch

File TerminalPosition.patch, 9.0 KB (added by rossi, 15 years ago)

Patch Rev. 2

  • src/apps/terminal/TermWindow.cpp

     
    11/*
    2  * Copyright 2007 Haiku, Inc.
     2 * Copyright 2007-2009 Haiku, Inc.
    33 * Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net>
    44 * Copyright (c) 2003-2004 Kian Duffy <myob@users.sourceforge.net>
    55 * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
     
    130130};
    131131
    132132
    133 TermWindow::TermWindow(BRect frame, const char* title, Arguments *args)
     133TermWindow::TermWindow(BRect frame, const char* title, uint32 workspaces, Arguments *args)
    134134    :
    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),
    137136    fInitialTitle(title),
    138137    fTabView(NULL),
    139138    fMenubar(NULL),
     
    168167        fFindPanel->Quit();
    169168        fFindPanel = NULL;
    170169    }
    171    
     170
    172171    PrefHandler::DeleteDefault();
    173172
    174173    for (int32 i = 0; Session* session = (Session*)fSessions.ItemAt(i); i++)
     
    615614}
    616615
    617616
     617bool
     618TermWindow::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
    618629void
    619630TermWindow::_SetTermColors(TermViewContainerView *containerView)
    620631{
  • src/apps/terminal/TermApp.h

     
    11/*
    2  * Copyright 2001-2008, Haiku.
     2 * Copyright 2001-2009, Haiku.
    33 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
    44 * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
    55 *
     
    3333
    3434
    3535#include <Application.h>
     36#include <File.h>
    3637#include <String.h>
    3738
    3839class Arguments;
     
    5253        void ArgvReceived(int32 argc, char** argv);
    5354
    5455    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);
    5660        void _SwitchTerm();
    5761        void _ActivateTermWindow(team_id id);
    5862        bool _IsSwitchTarget(team_id id);
     
    7579       
    7680        BWindow*    fTermWindow;
    7781        BRect       fTermFrame;
     82        uint32      fTermWorkspaces;
    7883        Arguments   *fArgs;
    7984};
    8085
  • src/apps/terminal/TermWindow.h

     
    11/*
    2  * Copyright 2001-2007, Haiku.
     2 * Copyright 2001-2009, Haiku.
    33 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
    44 * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
    55 *
     
    4848
    4949class TermWindow : public BWindow {
    5050public:
    51     TermWindow(BRect frame, const char* title, Arguments *args);
     51    TermWindow(BRect frame, const char* title, uint32 workspaces, Arguments *args);
    5252    virtual ~TermWindow();
    5353
    5454            void    SetSessionWindowTitle(TermView* termView,
     
    5959    virtual void    MessageReceived(BMessage *message);
    6060    virtual void    WindowActivated(bool);
    6161    virtual void    MenusBeginning();
    62 
     62    virtual bool    QuitRequested();
     63   
    6364private:
    6465    struct Session;
    6566    class TabView;
  • src/apps/terminal/TermApp.cpp

     
    11/*
    2  * Copyright 2001-2008, Haiku.
     2 * Copyright 2001-2009, Haiku.
    33 * Copyright (c) 2003-2004 Kian Duffy <myob@users.sourceforge.net>
    44 * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
    55 *
     
    1717
    1818#include <Alert.h>
    1919#include <Clipboard.h>
     20#include <FindDirectory.h>
     21#include <InterfaceDefs.h>
    2022#include <NodeInfo.h>
    2123#include <Path.h>
    2224#include <Roster.h>
     
    4547    fStartFullscreen(false),
    4648    fWindowNumber(-1),
    4749    fTermWindow(NULL),
     50    fTermWorkspaces(B_CURRENT_WORKSPACE),
    4851    fArgs(NULL)
    4952{
    5053    fArgs = new Arguments();
     
    5558    if (fWindowNumber > 0)
    5659        fWindowTitle << " " << fWindowNumber;
    5760
    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;
    6266
    63     fTermFrame.Set(k, l, k + 50, k + 50);
     67        fTermFrame.Set(k, l, k + 50, k + 50);
     68    }
    6469}
    6570
    6671
     
    98103    // init the mouse copy'n'paste clipboard
    99104    gMouseClipboard = new BClipboard(MOUSE_CLIPBOARD_NAME, true);
    100105
    101     status_t status = _MakeTermWindow(fTermFrame);
     106    status_t status = _MakeTermWindow(fTermFrame, fTermWorkspaces);
    102107
    103108    // failed spawn, print stdout and open alert panel
    104109    // TODO: This alert does never show up.
     
    119124void
    120125TermApp::Quit()
    121126{
     127    fTermWindow->PostMessage(B_QUIT_REQUESTED);
     128
    122129    if (!sUsageRequested)
    123130        _UnregisterTerminal();
    124131
     
    168175            break;
    169176        }
    170177
     178        case MSG_SAVE_WINDOW_POSITION:
     179            _SaveWindowPosition(msg);
     180            break;
     181           
    171182        case MSG_CHECK_CHILDREN:
    172183            _HandleChildCleanup();
    173184            break;
     
    236247
    237248
    238249status_t
    239 TermApp::_MakeTermWindow(BRect &frame)
     250TermApp::_GetWindowPositionsFile(BFile* file, uint32 openMode)
    240251{
     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
     264status_t
     265TermApp::_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
     306status_t
     307TermApp::_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
     365status_t
     366TermApp::_MakeTermWindow(BRect &frame, uint32 workspaces)
     367{
    241368    try {
    242         fTermWindow = new TermWindow(frame, fWindowTitle.String(), fArgs);
     369        fTermWindow = new TermWindow(frame, fWindowTitle.String(), workspaces, fArgs);
    243370    } catch (int error) {
    244371        return (status_t)error;
    245372    } catch (...) {
  • src/apps/terminal/TermConst.h

     
    11/*
    2  * Copyright 2001-2008, Haiku.
     2 * Copyright 2001-2009, Haiku.
    33 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
    44 * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
    55 *
     
    9292const uint32 MSG_SET_TERMNAL_TITLE              = 'sett';
    9393const uint32 MSG_QUIT_TERMNAL                   = 'qutt';
    9494
     95const uint32 MSG_SAVE_WINDOW_POSITION           = 'swps';
     96
    9597// Preference Read/Write Keys
    9698const char* const PREF_HALF_FONT_FAMILY = "Half Font Family";
    9799const char* const PREF_HALF_FONT_STYLE = "Half Font Style";