-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split every tab in two panes #206
base: master
Are you sure you want to change the base?
Changes from 1 commit
180472a
7080542
51816b8
e03bda2
240f1d8
e5226ed
43d04e7
e582ec2
5a6afe6
b8aa4b0
484ed1d
1cb1bc9
c1d0834
4088f70
a0618c0
9c06b97
bbcd3fa
6dd0c15
9568b68
8913213
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,9 +154,10 @@ import Termonad.PreferencesFile (saveToPreferencesFile) | |
import Termonad.Term | ||
( createTerms | ||
, relabelTabs | ||
, termExitFocused | ||
, termNextPage | ||
, termPrevPage | ||
, termExitFocused | ||
, termTogglePane | ||
, setShowTabs | ||
, showScrollbarToPolicy | ||
) | ||
|
@@ -393,17 +394,22 @@ setupTermonad tmConfig app win builder = do | |
else setShowTabs tmConfig note | ||
|
||
void $ onNotebookSwitchPage note $ \_ pageNum -> do | ||
modifyMVar_ mvarTMState $ \tmState -> do | ||
followUp <- modifyMVar mvarTMState $ \tmState -> do | ||
let notebook = tmStateNotebook tmState | ||
tabs = tmNotebookTabs notebook | ||
maybeNewTabs = updateFocusFL (fromIntegral pageNum) tabs | ||
case maybeNewTabs of | ||
Nothing -> pure tmState | ||
Nothing -> do | ||
pure (tmState, pure ()) | ||
Just (tab, newTabs) -> do | ||
widgetGrabFocus $ tab ^. lensTMNotebookTabFocusedTerm . lensTerm | ||
pure $ | ||
tmState & | ||
lensTMStateNotebook . lensTMNotebookTabs .~ newTabs | ||
let followUp = do | ||
let newFocus = tab ^. lensTMNotebookTabFocusedTerm . lensTerm | ||
widgetGrabFocus newFocus | ||
tmState' | ||
= tmState | ||
& lensTMStateNotebook . lensTMNotebookTabs .~ newTabs | ||
pure (tmState', followUp) | ||
followUp | ||
|
||
void $ onNotebookPageReordered note $ \childWidg pageNum -> do | ||
maybePaned <- castTo Paned childWidg | ||
|
@@ -433,17 +439,29 @@ setupTermonad tmConfig app win builder = do | |
actionMapAddAction app newTabAction | ||
applicationSetAccelsForAction app "app.newtab" ["<Shift><Ctrl>T"] | ||
|
||
nextPaneAction <- simpleActionNew "nextpane" Nothing | ||
void $ onSimpleActionActivate nextPaneAction $ \_ -> | ||
termTogglePane mvarTMState | ||
actionMapAddAction app nextPaneAction | ||
applicationSetAccelsForAction app "app.nextpane" ["<Ctrl>Page_Down"] | ||
|
||
prevPaneAction <- simpleActionNew "prevpane" Nothing | ||
void $ onSimpleActionActivate prevPaneAction $ \_ -> | ||
termTogglePane mvarTMState | ||
actionMapAddAction app prevPaneAction | ||
applicationSetAccelsForAction app "app.prevpane" ["<Ctrl>Page_Up"] | ||
|
||
nextPageAction <- simpleActionNew "nextpage" Nothing | ||
void $ onSimpleActionActivate nextPageAction $ \_ -> | ||
termNextPage mvarTMState | ||
actionMapAddAction app nextPageAction | ||
applicationSetAccelsForAction app "app.nextpage" ["<Ctrl>Page_Down"] | ||
applicationSetAccelsForAction app "app.nextpage" ["<Ctrl><Shift>Page_Down"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably a controversial change! Switching between tabs is a bigger change than switching between panes, and it makes more sense to me to use the the Shift version of the hotkey for the bigger change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with your reasoning here, although I don't personally use the I imagine I might have to finally start working on #83 ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, now that I think about it, this key combination only makes sense because with the two-panes approach, there is an obvious next-pane and prev-pane. Once arbitrary splittings are allowed, we'll need key combinations to move up, down, left and right, not prev and next. So I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left some example solutions here earlier.
|
||
|
||
prevPageAction <- simpleActionNew "prevpage" Nothing | ||
void $ onSimpleActionActivate prevPageAction $ \_ -> | ||
termPrevPage mvarTMState | ||
actionMapAddAction app prevPageAction | ||
applicationSetAccelsForAction app "app.prevpage" ["<Ctrl>Page_Up"] | ||
applicationSetAccelsForAction app "app.prevpage" ["<Ctrl><Shift>Page_Up"] | ||
|
||
closeTabAction <- simpleActionNew "closetab" Nothing | ||
void $ onSimpleActionActivate closeTabAction $ \_ -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ import GI.Gtk | |
, notebookSetTabReorderable | ||
, onButtonClicked | ||
, onWidgetButtonPressEvent | ||
, onWidgetFocusInEvent | ||
, onWidgetKeyPressEvent | ||
, scrolledWindowNew | ||
, scrolledWindowSetPolicy | ||
|
@@ -106,13 +107,16 @@ import Termonad.Lenses | |
, lensShowScrollbar | ||
, lensShowTabBar | ||
, lensTMNotebookTabFocusedTerm | ||
, lensTMNotebookTabFocusIsOnLeft | ||
, lensTMNotebookTabLabel | ||
, lensTMNotebookTabNonFocusedTerm | ||
, lensTMNotebookTabPaned | ||
, lensTMNotebookTabs | ||
, lensTMStateApp | ||
, lensTMStateConfig | ||
, lensTMStateNotebook | ||
, lensTerm | ||
, traversalTMNotebookFocusedTab | ||
) | ||
import Termonad.Types | ||
( ConfigHooks(createTermHook) | ||
|
@@ -142,6 +146,14 @@ focusTerm i mvarTMState = do | |
altNumSwitchTerm :: Int -> TMState -> IO () | ||
altNumSwitchTerm = focusTerm | ||
|
||
termTogglePane :: TMState -> IO () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there are only two panes, "nextPane" and "prevPane" are currently both equivalent to "togglePane". Once I implement recursively splitting the panes, "nextPane" and "prevPane" will become a lot more difficult, because the panes are layed out in 2D, not in 1D. I think moving up, down, left and right makes more sense than moving to the previous and next panes. I spent some time thinking about which semantics would make more sense for those movements, and simple algebraic operations for moving to a sibling node in the tree of panes didn't result in very natural movement; for example, if the panes are neatly organized as a 2x2 grid, moving right from the bottom left terminal might lead to the top-right terminal rather than the bottom-right. So the algorithm I currently have in mind is to plot the center points of all the terminals in 2D space, filter down to those points which are in the desired direction, e.g. if moving to the right, only looking at the center points whose X coordinates are larger than the current pane's X coordinate, then picking the remaining terminal whose center point is the closest to the current terminal in Euclidian or Manhattan distance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another good question. I'm not sure what would be the best idea here. I said it in https://github.com/cdepillabout/termonad/pull/206/files#r785424016 as well, but if I was going to implement this feature myself, I would probably start by taking a look at a few other programs that have panes and seeing exactly what operations they expose. And then try to work out how those operations work. Other than that, I don't really have any good suggestions. It sounds like you've definitely put more thought into this than I have! |
||
termTogglePane mvarTMState = do | ||
tabs <- tmNotebookTabs . tmStateNotebook <$> readMVar mvarTMState | ||
let maybeFocusedTab = getFocusItemFL tabs | ||
for_ maybeFocusedTab $ \focusedTab -> do | ||
let newFocus = focusedTab ^. lensTMNotebookTabNonFocusedTerm . lensTerm | ||
widgetGrabFocus newFocus | ||
|
||
termNextPage :: TMState -> IO () | ||
termNextPage mvarTMState = do | ||
note <- tmNotebook . tmStateNotebook <$> readMVar mvarTMState | ||
|
@@ -493,6 +505,19 @@ createTerms handleKeyPress mvarTMState = do | |
for_ @[ScrolledWindow] [scrolledWinL, scrolledWinR] $ \scrolledWin -> do | ||
void $ onWidgetKeyPressEvent scrolledWin $ handleKeyPress mvarTMState | ||
|
||
void $ onWidgetFocusInEvent vteTermL $ \_ -> do | ||
modifyMVar_ mvarTMState $ \tmState -> do | ||
pure $ tmState & lensTMStateNotebook | ||
. traversalTMNotebookFocusedTab | ||
. lensTMNotebookTabFocusIsOnLeft .~ True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, and in many other places, I really wasn't sure how to wrap lines around to match your style. Do you use a code formatter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used to use I think your code here is fine as-is. At some point I guess it would be nice to pick a code formatter and set it up to run automatically. |
||
pure False | ||
void $ onWidgetFocusInEvent vteTermR $ \_ -> do | ||
modifyMVar_ mvarTMState $ \tmState -> do | ||
pure $ tmState & lensTMStateNotebook | ||
. traversalTMNotebookFocusedTab | ||
. lensTMNotebookTabFocusIsOnLeft .~ False | ||
pure False | ||
|
||
-- Put the keyboard focus on the left term | ||
setFocusOn tmStateAppWin vteTermL | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad you were able to figure out how to do this. I should really document the need to pull out these types of follow-up IO actions and run them after modifying the
MVar
. Hope this didn't take too long to figure out.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't too bad; my initial attempt deadlocked, but I was able to figure out by adding a few print statements here and there.