Ticket #1746: virtualmemory-fixes.diff

File virtualmemory-fixes.diff, 6.6 KB (added by hamish, 13 years ago)

Fixes more issues with VirtualMemory noted while fixing #1746

  • Settings.cpp

     
    203203    fSwapVolume.SetTo(fInitialSwapVolume);
    204204}
    205205
    206 
     206// This function makes no sense...
     207// Why should defaultable depend on whether the settings have
     208// changed or not?
    207209bool
    208210Settings::IsDefaultable()
    209211{
  • SettingsWindow.cpp

     
    127127    fSwapEnabledCheckBox = new BCheckBox("enable swap",
    128128        B_TRANSLATE("Enable virtual memory"),
    129129        new BMessage(kMsgSwapEnabledUpdate));
    130     fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
    131130
    132131    BBox* box = new BBox("box", B_FOLLOW_LEFT_RIGHT);
    133132    box->SetLabel(fSwapEnabledCheckBox);
     
    163162            item->SetMarked(true);
    164163    }
    165164
    166     BMenuField* field = new BMenuField("devices", B_TRANSLATE("Use volume:"),
    167         menu);
    168     field->SetEnabled(false);
    169 
    170     off_t minSize, maxSize;
    171     _GetSwapFileLimits(minSize, maxSize);
    172 
    173     fSizeSlider = new SizeSlider("size slider",
    174         B_TRANSLATE("Requested swap file size:"),
    175         new BMessage(kMsgSliderUpdate), minSize / kMegaByte, maxSize / kMegaByte,
    176         B_WILL_DRAW | B_FRAME_EVENTS);
    177     fSizeSlider->SetLimitLabels(B_TRANSLATE("999 MB"), B_TRANSLATE("999 MB"));
     165    fVolumeMenuField = new BMenuField("devices", B_TRANSLATE("Use volume:"), menu);
     166   
     167    // When swap volume changing support is implemeneted, remove me:
     168    fVolumeMenuField->SetEnabled(false);
     169   
     170    fSizeSlider = new SizeSlider("size slider",
     171        B_TRANSLATE("Requested swap file size:"), new BMessage(kMsgSliderUpdate),
     172        0, 0, B_WILL_DRAW | B_FRAME_EVENTS);
    178173    fSizeSlider->SetViewColor(255, 0, 255);
    179174
    180175    fWarningStringView = new BStringView("", "");
     
    191186            .AddGlue()
    192187        .End()
    193188        .AddGroup(B_HORIZONTAL)
    194             .Add(field)
     189            .Add(fVolumeMenuField)
    195190            .AddGlue()
    196191        .End()
    197192        .Add(fSizeSlider)
     
    226221    BScreen screen;
    227222    BRect screenFrame = screen.Frame();
    228223
    229     if (!screenFrame.Contains(fSettings.WindowPosition())) {
    230         // move on screen, centered
     224    if (!screenFrame.Contains(fSettings.WindowPosition()))
    231225        CenterOnScreen();
    232     } else
     226    else
    233227        MoveTo(fSettings.WindowPosition());
    234228}
    235229
     
    239233}
    240234
    241235
    242     void
     236void
    243237SettingsWindow::_Update()
    244238{
    245239    if ((fSwapEnabledCheckBox->Value() != 0) != fSettings.SwapEnabled())
    246240        fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
     241       
     242    if (fSizeSlider->IsEnabled() != fSettings.SwapEnabled())
     243        fSizeSlider->SetEnabled(fSettings.SwapEnabled());
     244   
     245#ifdef SWAP_VOLUME_IMPLEMENTED 
     246    if (fVolumeMenuField->IsEnabled() != fSettings.SwapEnabled())
     247        fVolumeMenuField->SetEnabled(fSettings.SwapEnabled());
     248#endif
    247249
    248250    off_t minSize, maxSize;
    249251    if (_GetSwapFileLimits(minSize, maxSize) == B_OK) {
     
    251253        minLabel << byte_string(minSize);
    252254        maxLabel << byte_string(maxSize);
    253255        if (minLabel != fSizeSlider->MinLimitLabel()
    254                 || maxLabel != fSizeSlider->MaxLimitLabel()) {
     256            || maxLabel != fSizeSlider->MaxLimitLabel()) {
    255257            fSizeSlider->SetLimitLabels(minLabel.String(), maxLabel.String());
    256258#ifdef __HAIKU__
    257259            fSizeSlider->SetLimits(minSize / kMegaByte, maxSize / kMegaByte);
     
    260262
    261263        if (fSizeSlider->Value() != fSettings.SwapSize() / kMegaByte)
    262264            fSizeSlider->SetValue(fSettings.SwapSize() / kMegaByte);
    263 
    264         fSizeSlider->SetEnabled(true);
    265265    } else {
    266         fSizeSlider->SetValue(minSize);
     266        // Not enough space on volume for a swap file. Make UI inoperable.
     267        fWarningStringView->SetText(
     268            B_TRANSLATE("Insufficient space for a swap file."));
     269        fSwapEnabledCheckBox->SetEnabled(false);
    267270        fSizeSlider->SetEnabled(false);
     271        // When swap volume is implemented, we'll want to keep the volume
     272        // menu field enabled so the user can get around the space issue
     273        // by selecting a different volume.
     274#ifdef SWAP_VOLUME_IMPLEMENTED
     275        fVolumeMenuField->SetEnabled(true);
     276#endif
    268277    }
    269278
    270279    // ToDo: set volume
     
    283292}
    284293
    285294
    286     status_t
     295status_t
    287296SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize)
    288297{
    289     // minimum size is an arbitrarily chosen MB
    290298    minSize = kMegaByte;
    291299
    292300    // maximum size is the free space on the current volume
    293301    // (minus some safety offset, depending on the disk size)
    294 
    295302    off_t freeSpace = fSettings.SwapVolume().FreeBytes();
    296303    off_t safetyFreeSpace = fSettings.SwapVolume().Capacity() / 100;
    297304    if (safetyFreeSpace > 1024 * kMegaByte)
     
    299306
    300307    // check if there already is a page file on this disk and
    301308    // adjust the free space accordingly
    302 
    303309    BPath path;
    304310    if (find_directory(B_COMMON_VAR_DIRECTORY, &path, false,
    305             &fSettings.SwapVolume()) == B_OK) {
     311        &fSettings.SwapVolume()) == B_OK) {
    306312        path.Append("swap");
    307313        BEntry swap(path.Path());
    308314
    309315        off_t size;
    310         if (swap.GetSize(&size) == B_OK)
     316        if (swap.GetSize(&size) == B_OK) {
     317            // If swap file exists, forget about safety space;
     318            // disk may have filled after creation of swap file.
     319            safetyFreeSpace = 0;
    311320            freeSpace += size;
     321        }
    312322    }
    313323
    314324    maxSize = freeSpace - safetyFreeSpace;
    315 
    316325    if (maxSize < minSize) {
    317         maxSize = minSize;
     326        maxSize = minSize = 0;
    318327        return B_ERROR;
    319328    }
    320329
     
    347356            if (value == 0) {
    348357                // print out warning, give the user the time to think about it :)
    349358                // ToDo: maybe we want to remove this possibility in the GUI
    350                 //  as Be did, but I thought a proper warning could be helpful
    351                 //  (for those that want to change that anyway)
     359                // as Be did, but I thought a proper warning could be helpful
     360                // (for those that want to change that anyway)
    352361                int32 choice = (new BAlert("VirtualMemory",
    353362                    B_TRANSLATE(
    354363                    "Disabling virtual memory will have unwanted effects on "
     
    365374            }
    366375
    367376            fSettings.SetSwapEnabled(value != 0);
     377            if (value == 1 && fSettings.SwapSize() == 0)
     378            {
     379                off_t min, max;
     380                _GetSwapFileLimits(min, max);
     381                fSettings.SetSwapSize(min);
     382            }
    368383            _Update();
    369384            break;
    370385        }
  • SettingsWindow.h

     
    1414class BCheckBox;
    1515class BSlider;
    1616class BButton;
     17class BMenuField;
    1718
    18 
    1919class SettingsWindow : public BWindow {
    2020    public:
    2121        SettingsWindow();
     
    3333        BButton*        fDefaultsButton;
    3434        BButton*        fRevertButton;
    3535        BStringView*    fWarningStringView;
    36 
     36        BMenuField*     fVolumeMenuField;
    3737        Settings        fSettings;
    3838};
    3939