Ticket #7132: Deskbar Resize Team Icons 4.diff

File Deskbar Resize Team Icons 4.diff, 8.3 KB (added by jscipione, 10 years ago)

Resize Deskbar Icons Patch

  • src/apps/deskbar/BarApp.cpp

    diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp
    index 532e1bc..1e3113a 100644
    a b BList TBarApp::sSubscribers;  
    7272const uint32 kShowBeMenu = 'BeMn';
    7373const uint32 kShowTeamMenu = 'TmMn';
    7474
    75 const BRect kIconSize(0.0f, 0.0f, 15.0f, 15.0f);
    7675
     76const BRect kIconRect(0.0f, 0.0f, 15.0f, 15.0f);
    7777static const color_space kIconFormat = B_RGBA32;
    7878
    7979
    TBarApp::TBarApp()  
    119119    fBarWindow = new TBarWindow();
    120120    fBarWindow->Show();
    121121
     122    fBarView = static_cast<TBarApp*>(be_app)->BarView();
     123
    122124    // this messenger now targets the barview instead of the
    123125    // statusview so that all additions to the tray
    124126    // follow the same path
    TBarApp::SaveSettings()  
    208210            fSettings.superExpando);
    209211        storedSettings.AddBool("expandNewTeams",
    210212            fSettings.expandNewTeams);
     213        storedSettings.AddInt32("iconSize",
     214            fSettings.iconSize);
    211215        storedSettings.AddBool("autoRaise",
    212216            fSettings.autoRaise);
    213217        storedSettings.AddBool("recentAppsEnabled",
    TBarApp::InitSettings()  
    244248    settings.sortRunningApps = false;
    245249    settings.superExpando = false;
    246250    settings.expandNewTeams = false;
     251    settings.iconSize = 1;
    247252    settings.autoRaise = false;
    248253    settings.recentAppsEnabled = true;
    249254    settings.recentDocsEnabled = true;
    TBarApp::InitSettings()  
    295300                &settings.superExpando);
    296301            storedSettings.FindBool("expandNewTeams",
    297302                &settings.expandNewTeams);
     303            storedSettings.FindInt32("iconSize",
     304                (int32*)&settings.iconSize);
    298305            storedSettings.FindBool("autoRaise",
    299306                &settings.autoRaise);
    300307            storedSettings.FindBool("recentAppsEnabled",
    TBarApp::MessageReceived(BMessage* message)  
    478485            break;
    479486        }
    480487
     488        case kResizeTeamIcons:
     489        {
     490            int32 iconSize;
     491
     492            if (message->FindInt32("be:value", &iconSize) == B_OK)
     493                fSettings.iconSize = iconSize;
     494
     495            if (fSettings.iconSize < 1)
     496                fSettings.iconSize = 1;
     497            else if (fSettings.iconSize > 4)
     498                fSettings.iconSize = 4;
     499
     500            ResizeTeamIcons();
     501
     502            fBarWindow->Lock();
     503            fBarView->UpdatePlacement();
     504            fBarWindow->Unlock();
     505            break;
     506        }
     507
    481508        case 'TASK':
    482509            fSwitcherMessenger.SendMessage(message);
    483510            break;
    TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref)  
    628655        return;
    629656    }
    630657
    631     BFile file(ref, B_READ_ONLY);
    632     BAppFileInfo appMime(&file);
    633 
    634658    BarTeamInfo* barInfo = new BarTeamInfo(new BList(), flags, strdup(sig),
    635         new BBitmap(kIconSize, kIconFormat), strdup(ref->name));
     659        new BBitmap(kIconRect, kIconFormat), strdup(ref->name));
    636660
    637661    barInfo->teams->AddItem((void*)team);
    638     if (appMime.GetIcon(barInfo->icon, B_MINI_ICON) != B_OK)
    639         appMime.GetTrackerIcon(barInfo->icon, B_MINI_ICON);
    640662
    641663    sBarTeamInfoList.AddItem(barInfo);
     664    BMessage message(kResizeTeamIcons);
     665    be_app->PostMessage(&message);
    642666
    643667    int32 subsCount = sSubscribers.CountItems();
    644668    if (subsCount > 0) {
    TBarApp::RemoveTeam(team_id team)  
    698722
    699723
    700724void
     725TBarApp::ResizeTeamIcons()
     726{
     727    BRect iconRect;
     728
     729    if (fBarView->Vertical())
     730        iconRect = BRect(0, 0, ((fSettings.iconSize * 16) - 1),
     731            ((fSettings.iconSize * 16) - 1));
     732    else
     733        iconRect = kIconRect;
     734
     735    for (int32 i = 0; i < sBarTeamInfoList.CountItems(); i++) {
     736        BarTeamInfo* barInfo = (BarTeamInfo*)sBarTeamInfoList.ItemAt(i);
     737        if ((barInfo->flags & B_BACKGROUND_APP) == 0
     738            && strcasecmp(barInfo->sig, kDeskbarSignature) != 0) {
     739            barInfo->icon = new BBitmap(iconRect, kIconFormat);
     740            FetchAppIcon(barInfo->sig, barInfo->icon);
     741        }
     742    }
     743}
     744
     745
     746void
    701747TBarApp::ShowPreferencesWindow()
    702748{
    703749    if (fPreferencesWindow)
    TBarApp::ShowPreferencesWindow()  
    709755}
    710756
    711757
     758void
     759TBarApp::FetchAppIcon(const char* signature, BBitmap* icon)
     760{
     761    app_info appInfo;
     762
     763    if (be_roster->GetAppInfo(signature, &appInfo) == B_OK) {
     764        BFile file(&appInfo.ref, B_READ_ONLY);
     765        BAppFileInfo appMime(&file);
     766        if (fBarView->Vertical() && icon->Bounds().IntegerHeight() > 15) {
     767            if (appMime.GetIcon(icon, B_LARGE_ICON) != B_OK)
     768                appMime.GetTrackerIcon(icon, B_LARGE_ICON);
     769        } else {
     770            if (appMime.GetIcon(icon, B_MINI_ICON) != B_OK)
     771                appMime.GetTrackerIcon(icon, B_MINI_ICON);
     772        }
     773    }
     774}
     775
     776
    712777//  #pragma mark -
    713778
    714779
  • src/apps/deskbar/BarApp.h

    diff --git a/src/apps/deskbar/BarApp.h b/src/apps/deskbar/BarApp.h
    index 6f15838..3e9aefe 100644
    a b const uint32 kTrackerFirst = 'TkFt';  
    8080const uint32 kSortRunningApps = 'SAps';
    8181const uint32 kSuperExpando = 'SprE';
    8282const uint32 kExpandNewTeams = 'ExTm';
     83const uint32 kResizeTeamIcons = 'RTIs';
    8384const uint32 kAutoRaise = 'AtRs';
    8485const uint32 kRestartTracker = 'Trak';
    8586
    struct desk_settings {  
    109110    bool sortRunningApps;
    110111    bool superExpando;
    111112    bool expandNewTeams;
     113    int32 iconSize;
    112114    bool autoRaise;
    113115    bool recentAppsEnabled;
    114116    bool recentDocsEnabled;
    class TBarApp : public BApplication {  
    139141
    140142        static void Subscribe(const BMessenger &subscriber, BList*);
    141143        static void Unsubscribe(const BMessenger &subscriber);
     144        void ResizeTeamIcons();
    142145
    143146    private:
    144147        void AddTeam(team_id team, uint32 flags, const char *sig, entry_ref *);
    class TBarApp : public BApplication {  
    148151        void SaveSettings();
    149152
    150153        void ShowPreferencesWindow();
     154        void FetchAppIcon(const char* signature, BBitmap* icon);
    151155
    152156        TBarWindow* fBarWindow;
     157        TBarView* fBarView;
    153158        BMessenger fSwitcherMessenger;
    154159        BMessenger fStatusViewMessenger;
    155160        BFile* fSettingsFile;
  • src/apps/deskbar/BarView.cpp

    diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp
    index f113e6a..92c9c0a 100644
    a b TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)  
    439439    fLeft = left;
    440440    fTop = top;
    441441
     442    // If switching vertical orientation resize the icons
     443    if (vertSwap)
     444        static_cast<TBarApp*>(be_app)->ResizeTeamIcons();
     445
    442446    BRect screenFrame = (BScreen(Window())).Frame();
    443447
    444448    PlaceBeMenu();
  • src/apps/deskbar/PreferencesWindow.cpp

    diff --git a/src/apps/deskbar/PreferencesWindow.cpp b/src/apps/deskbar/PreferencesWindow.cpp
    index e8fdf07..54ce455 100644
    a b  
    1717#include <OpenWithTracker.h>
    1818#include <RadioButton.h>
    1919#include <SeparatorView.h>
     20#include <Slider.h>
    2021
    2122#include <ctype.h>
    2223
    PreferencesWindow::PreferencesWindow(BRect frame)  
    5758        new BMessage(kSuperExpando));
    5859    fAppsExpandNew = new BCheckBox(B_TRANSLATE("Expand new applications"),
    5960        new BMessage(kExpandNewTeams));
     61    fAppsIconSizeSlider = new BSlider("icon_size", B_TRANSLATE("Icon size"),
     62        new BMessage(kResizeTeamIcons), 1, 4, B_HORIZONTAL);
     63    fAppsIconSizeSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
     64    fAppsIconSizeSlider->SetHashMarkCount(4);
     65    fAppsIconSizeSlider->SetLimitLabels(B_TRANSLATE("Small"),
     66        B_TRANSLATE("Large"));
    6067
    6168    fClockSeconds = new BCheckBox(B_TRANSLATE("Show seconds"),
    6269        new BMessage(kShowSeconds));
    PreferencesWindow::PreferencesWindow(BRect frame)  
    8996    fAppsSortTrackerFirst->SetValue(appSettings->trackerAlwaysFirst);
    9097    fAppsShowExpanders->SetValue(appSettings->superExpando);
    9198    fAppsExpandNew->SetValue(appSettings->expandNewTeams);
     99    fAppsIconSizeSlider->SetValue(appSettings->iconSize);
    92100
    93101    int32 docCount = appSettings->recentDocsCount;
    94102    int32 appCount = appSettings->recentAppsCount;
    PreferencesWindow::PreferencesWindow(BRect frame)  
    131139    fAppsSort->SetTarget(be_app);
    132140    fAppsSortTrackerFirst->SetTarget(be_app);
    133141    fAppsExpandNew->SetTarget(be_app);
     142    fAppsIconSizeSlider->SetTarget(be_app);
    134143
    135144    fClockSeconds->SetTarget(replicantTray);
    136145
    PreferencesWindow::PreferencesWindow(BRect frame)  
    179188                .SetInsets(20, 0, 0, 0)
    180189                .Add(fAppsExpandNew)
    181190                .End()
     191            .Add(fAppsIconSizeSlider)
    182192            .AddGlue()
    183193            .SetInsets(10, 10, 10, 10)
    184194            .End()
  • src/apps/deskbar/PreferencesWindow.h

    diff --git a/src/apps/deskbar/PreferencesWindow.h b/src/apps/deskbar/PreferencesWindow.h
    index 77f641b..415e813 100644
    a b  
    1010#include <Button.h>
    1111#include <CheckBox.h>
    1212#include <RadioButton.h>
     13#include <Slider.h>
    1314#include <StringView.h>
    1415#include <TextControl.h>
    1516#include <Window.h>
    private:  
    5152            BCheckBox*      fAppsSortTrackerFirst;
    5253            BCheckBox*      fAppsShowExpanders;
    5354            BCheckBox*      fAppsExpandNew;
     55            BSlider*        fAppsIconSizeSlider;
    5456
    5557            BCheckBox*      fClockSeconds;
    5658